Java Date UTC Parse getUtcDate(Date date)

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

Description

get Utc Date

License

Open Source License

Declaration

public static Date getUtcDate(Date date) 

Method Source Code


//package com.java2s;
/*/* w w w . j a v a 2 s .c  o m*/
 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

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

public class Main {
    public static Date getUtcDate(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        TimeZone z = calendar.getTimeZone();
        int offset = z.getRawOffset();
        if (z.inDaylightTime(new Date())) {
            offset = offset + z.getDSTSavings();
        }
        int offsetHrs = offset / 1000 / 60 / 60;
        int offsetMins = offset / 1000 / 60 % 60;

        calendar.add(Calendar.HOUR_OF_DAY, (-offsetHrs));
        calendar.add(Calendar.MINUTE, (-offsetMins));

        return calendar.getTime();
    }
}

Related

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