Saving date giving incorrect results .

10 views
Skip to first unread message

Tanzim Islam

unread,
Jun 1, 2020, 5:46:07 AM6/1/20
to Back4App
Hello 
I'm coding in java on android and using the calendar class to handle dates.

Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH,1);
        cal.set(Calendar.HOUR_OF_DAY, 2);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        obj.put("paymentDate",cal.getTime());

As you can see above , I added a day to the day of month , so today is 1st of june , it would be 2nd of june
and also I set the hour to 02 , and others to zero.
I put out a toast for getTime() and it gives me correct results.
But in my database this is being saved.

2020-06-01T20:00:00.000Z (Which means first of June , with hour of 20)

Please help

ali öksüz

unread,
Jun 1, 2020, 8:28:08 AM6/1/20
to Back4App
Database saves time for UTC-0(Greenwich - fist meridian of world). When you get your time in Java code, Java propabloy converts it to local time, if it dont convert it yourself
Reply all
Reply to author
Forward
0 new messages