Android Date to UTC Convert currentDateInUTC()

Here you can find the source of currentDateInUTC()

Description

current Date In UTC

Declaration

public static Date currentDateInUTC() 

Method Source Code

//package com.java2s;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static Date currentDateInUTC() {
        return new Date(getUTCTimeMillis());
    }/*from  w w  w.  j  av  a  2 s.c  o m*/

    /**
     * @return current UTC time in milliseconds taking into account timezone and
     *         dst offset
     */
    static long getUTCTimeMillis() {
        return getUTCTimeFromLocalMillis(System.currentTimeMillis());
    }

    /**
     * Convert a local timestamp into UTC time
     * 
     * @param localTimeMillis
     * @return
     */
    static long getUTCTimeFromLocalMillis(long localMillis) {
        return localMillis + getTimeZoneOffsetInMillis();
    }

    /**
     * @return the timezone offset of the current device relative to UTC
     */
    static long getTimeZoneOffsetInMillis() {
        Calendar cal = Calendar.getInstance();
        return cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
    }
}

Related

  1. nowUTC()
  2. localDateToUTC(Date dtLocal)
  3. getCalendarInUTC(String date)
  4. getDateInUTC(String date)