scala - Always get "1970" when extracting a year from timestamp -
i have timestamp "1461819600". execute code in distributed environment val campaign_startdate_year: string = utils.getyear(campaign_startdate_timestamp).tostring
the problem same year 1970
. might reason of it?
import com.github.nscala_time.time.imports._ def getyear(timestamp: any): int = { var dt = 2017 if (!timestamp.tostring.isempty) { dt = new datetime(timestamp.tostring.tolong).getyear // tolong should multiplied 1000 millisecond value } dt }
the same issue occurs when want day of month. 17
instead of 28
.
def getday(timestamp: any): int = { var dt = 1 if (!timestamp.tostring.isempty) { dt = new datetime(timestamp.tostring.tolong).getdayofyear } dt }
the timestamp have number of seconds since 01-01-1970, 00:00:00 utc.
java (and scala) use timestamps number of milliseconds since 01-01-1970, 00:00:00 utc.
in other words, need multiply number 1000.
Comments
Post a Comment