Java Date UTC Parse toUTC(Date date)

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

Description

Convert the specified date from local time zone to UTC time zone.

License

Open Source License

Parameter

Parameter Description
date The date to be converted.

Return

The converted date

Declaration

public static Date toUTC(Date date) 

Method Source Code

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

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Main {
    /**/*w  w  w  .  ja va2  s.  c om*/
     * Convert the specified date from local time zone to UTC time zone.
     * @param date The date to be converted.
     * @return The converted date
     */
    public static Date toUTC(Date date) {
        Calendar cal = new GregorianCalendar(TimeZone.getDefault());
        cal.setTime(date);
        cal.setTimeZone(TimeZone.getTimeZone("UTC"));

        return cal.getTime();
    }
}

Related

  1. parseDateAsUTC(String dateString)
  2. parsePartialUTCToDate(String utcDate)
  3. parseToUTCDate(String timestamp, String pattern)
  4. parseUTCDateToString(Date date)
  5. parseUTCToDate(String utcDate)
  6. toUTC(Date date)
  7. toUTC(Date date)
  8. uTCToChinaTS(Date date)
  9. UTCToDate(long utcValue)