Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
/**
* ExcelDateParse: Parses a Java Date from an Excel Date Format
* {talendTypes} String
* {Category} User Defined
* {param} int(date) input: the excel date int to convert
* {example} ExcelDateParse(38838) # result: Tue May 02 00:00:00 PDT 2006
*/
public static Date ExcelDateParse(int ExcelDate){
Date result = null;
try{
GregorianCalendar gc = new GregorianCalendar(1900, Calendar.JANUARY, 1);
gc.add(Calendar.DATE, ExcelDate - 1);
result = gc.getTime();
} catch(RuntimeException e1) {}
return result;
}
/**
* ExcelTimeParse: Parses a Java Time String from an Excel Formated Time
* {talendTypes} String
* {Category} User Defined
* {param} String(date) input: the excel time String to convert
* {example} ExcelTimeParse("0.6549") # result: 15:43:03 PM
*/
public static String ExcelTimeParse(String ExcelDate){
String result = "";
try{
DateFormat format = new SimpleDateFormat("HH:mm:ss a");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
double frac = Double.parseDouble(ExcelDate);
long day = (long) Math.floor(frac);
frac = frac - day;
Date time = new Date((long) ( 86400000l * frac));
result = format.format(time);
} catch(RuntimeException e1) {}
return result;
}
// this next one is a Work in progress and not functional:
/**
* ExcelTimeParse: Parses a Java Time String from an Excel Formated Time
* {talendTypes} String
* {Category} User Defined
* {param} String(date) input: the excel time String to convert
* {example} ExcelTimeParse("38838.6549") # result: Tue May 02 15:43:03 PM
*/
public static String ExcelDateTimeParse(String ExcelDateTime, String DateFormat){
String DefaultFormat = "MM/dd/yyyy HH:mm:ss a";
String result = "";
if(DateFormat.isEmpty()){
DateFormat = DefaultFormat;
}
try{
DateFormat format = new SimpleDateFormat(DateFormat);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
double frac = Double.parseDouble(ExcelDateTime);
long day = (long) Math.floor(frac);
frac = frac - day;
Date time = new Date((long) ( 86400000l * frac));
result = format.format(time);
} catch(RuntimeException e1) {}
return result;
}