business-intelligence/talend/jobs/LOCAL_PROJECT/code/routines/user/JavaDateEpoch_0.1.item
2019-04-21 17:42:10 +02:00

44 lines
1.1 KiB
Plaintext

package routines;
import java.text.SimpleDateFormat;
import java.util.Date;
/*
* getDateFromEpoch: return yyyyMMdd from timestamp epoch
*
*
* {talendTypes} Long
*
* {Category} User Defined
*
* {param} Long(Long) input: The timestamp to convert
*
* {example} getDateFromEpoch(epoch)
*/
public class JavaDateEpoch {
/**
* get part of date. like YEAR, MONTH, HOUR, or DAY_OF_WEEK, WEEK_OF_MONTH, WEEK_OF_YEAR, TIMEZONE and so on
*
* @param partName which part to get.
* @param date the date value.
* @return the specified part value.
*
* {talendTypes} Long
*
* {Category} User Defined
*
* {param} Long(Long) input: The timestamp to convert
*
* {example} getDateFromEpoch(epoch)
*
*/
public static Long getDateFromEpoch(Long timeAsLong){
Long returnVal = null;
if(timeAsLong!=null){
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String v = sdf.format(new Date(timeAsLong));
returnVal = Long.parseLong(v);
}
return returnVal;
}
}