UTC stands for Coordinated Universal Time. It is the common time standard across the world.
In order to get the date-time in UTC, we need to set the timezone in UTC, like this:-
Step 1
Define your format in which you want to get date/time:-
String format = "yyyy/MM/dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(format);
Step 2
Set the TimeZone of SimpleDateFormat in UTC
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Step 3
Get date/time string in UTC
sdf.format(date)
Now you can parse this UTC String in date datatype.
Note:- In order to parse String in Date visit this link
0 Comment(s)