Reputation: 23
I am trying to convert a unix time to datetime depending on its locale given
Example I wanted to get locale Australia and convert UNIX time to date:
<#setting locale= getlocale>
<#assign unix = "1660545165"?number>
<#assign expiryDate = unix.getstarttime()?number?number_to_datetime?string["yyyy-mm-dd"]>
here is the time ${expiryDate}
I searched in google and suggested me to use getstarttime()?number?number_to_datetime?string["yyyy-mm-dd"] However I am getting an error and currently stuck: Expected a hash, but this has evaluated to a number
Upvotes: 0
Views: 214
Reputation: 31152
Lot of what's wrong I think is simply unnecessary there. Also based on the format you actually want a date, not a date-time. Here's a working example:
<#assign unixTime = 1660545165>
Here is the time: ${unixTime?number_to_date?string["yyyy-MM-dd"]}
Also usually you want to set the date_format
setting to yyyy-MM-dd
once (in the Java code, or with <#setting date_format = "yyyy-MM-dd">
near the top of the the template), and then just write ${unixTime?number_to_date}
everywhere.
Upvotes: 1