This question already has an answer here:
-
Java: How to get current date in ISO 8601 SECOND format
2 answers
I have the TimeStamp
and I need to convert it to Data
type object that should match this pattern - "2016-11-16T18:42:33.049Z". How can I do that?
Date d = new Date((long)timestamp*1000);
will create a Date
instance. Displaying it later is another thing.
I think it's what you want:
DateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.mmm'Z'");
System.out.println(f.format(date));
Test:
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String[] args) throws Exception {
Date d = new Date((long)1481723817*1000);
DateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.mmm'Z'");
System.out.println(f.format(d));
}
}
>>2016-12-14T14:56:57.056Z
Convert like this.
String date = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new java.util.Date (epoch*1000));
you can also use the data object in the manner u want.