简体   繁体   中英

How to convert Google API DateTime timestamp between Cloud and local time

        //Push Insert a Task:
  Calendar calendar = Calendar.getInstance();
  long timestampToDB = calendar.getTimeInMillis();
    com.google.api.services.tasks.model.Task newTask = new com.google.api.services.tasks.model.Task();
    newTask.setTitle("New Task");
    DateTime timeStampLocale = new DateTime(calendar.getTime(), calendar.getTimeZone());
    newTask.setUpdated(timeStampLocale);

    //Pull the Task:
    com.google.api.services.tasks.model.Task theTask = Tasks.geTaskById(String taskId);
    DateTime timeStampCloud = theTask.getUpdated();

    //Compare Timestamp:
    //How to compare the two timestamp, in order to see which timestamp one is latest

I had "timeStampCloud" and "timestampToDB", but how to campare the two timestamp? if the device timezone changed, what it will be going to happen. Please help!! :)

   DateFormat formatter= new SimpleDateFormat("MM/dd/yyyy HH:mm:ss Z");
 formatter.setTimeZone(TimeZone.getTimeZone("Europe/London"));
 System.out.println(formatter.format(date));
 formatter.setTimeZone(TimeZone.getTimeZone("Europe/Athens")); System.out.println(formatter.format(instance2.getTime()))

Get timezone of google date.. According to that time convert your date to google timezone.. as shown in above examples. Now you compare both dates..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM