I searched for solutions but still not working ,I'm trying to convert the date object's local timezone to UTC +0 , but when i format the date object to UTC it's working . but when I want to convert the converted string to date again, the format changes and UTC goes back to GMT+8 before i store it in the fire store. what is the problem in the code?
this is the current date object that i get
Calendar time = Calendar.getInstance();
time.setTimeZone(TimeZone.getTimeZone("UTC"));
Date current_time = time.getTime();
if printed
Thu Aug 22 10:09:55 GMT+08:00 2019
then i convert it to UTC
String dismissal_time_firestore;
Log.i(TAG, "Current time when swiped from phone time.getTime() "+current_time);
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
dismissal_time_firestore = dateFormat.format(current_time);
got this
Thu, 22 Aug 2019 02:09:55 +0000
but then when i convert this string to a date object
try {
current_time = dateFormat.parse(dismissal_time_firestore);
} catch (ParseException e) {
e.printStackTrace();
}
i got this
Thu Aug 22 10:09:55 GMT+08:00 2019