I have a date as long value, I want to display the Date format in words depends upon the country time zone. Please help me in converting this.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
You need to understand date as long value is the absolute value (UTC) of time in milli seconds since Epoch i.e. '1st Jan 1970 00:00:00'. This value has no timezone information embedded in it. Now if you want to display this time in your current local timezone then simply do this:
It prints:
Note the when it prints the date it automatically prints it with my current timezone.
However if you want customized formattng to display your date then you can take a look at the DateFormat class in Java.
Take a look at the
java.text.DateFormat
class. It provides several option how to output the current Data and Time.For example the following code prints the current date and time in the long format option for the en_UK locale:
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.UK).format(new Date());
Prints:
23 January 2012 08:17:36 CET
To display any date, just pass the long value to the constructor of the
Date
object.DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.UK).format(new Date(<your long value here>));