Java Date UTC Parse getUTCDate(Date date)

Here you can find the source of getUTCDate(Date date)

Description

Converts local time to UTC time properly

License

Open Source License

Parameter

Parameter Description
date the Date object

Return

date converted to UTC

Declaration

public static Date getUTCDate(Date date) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;

import java.util.Date;

public class Main {
    /**// ww  w.  j a  va  2 s.c o  m
     * Converts local time to UTC time properly
     * @param date the Date object
     * @return date converted to <b>UTC</b>
     */
    public static Date getUTCDate(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(date.getTime() - cal.getTimeZone().getOffset(date.getTime()));
        return cal.getTime();
    }
}

Related

  1. getLocalTimeFromUTC( String localTimeZoneId, java.util.Date utcTimestamp)
  2. getUTC(java.util.Date siteTimestamp)
  3. getUTCDate()
  4. getUTCDate()
  5. getUTCDate()
  6. getUtcDate(Date date)
  7. getUtcDate(final int year, final int month, final int day)
  8. getUTCDate(int year, int month, int date, int h, int m, int s, int milli)
  9. getUTCDate(int year, int month, int day)