Java Calendar UTC getCalendarUTC()

Here you can find the source of getCalendarUTC()

Description

get Calendar UTC

License

Open Source License

Declaration

private static Calendar getCalendarUTC() 

Method Source Code


//package com.java2s;
/*/*ww  w  .  j a v a2 s.co m*/
*
* Copyright 2015 IK4-Tekniker All Rights Reserved
*
* This file is part of Health Questionnaire SE at FISTAR https://www.fi-star.eu/  
*
* Health Questionnaire SE is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Health Questionnaire SE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Health Questionnaire SE. If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by this license please contact with
* patricia.casla at tekniker dot es
*
* Author: Ignacio Lazaro Llorente
*/

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

public class Main {
    private static Calendar getCalendarUTC() {
        Calendar c = Calendar.getInstance();
        System.out.println("current: " + c.getTime());

        TimeZone z = c.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;

        System.out.println("offsetHrs: " + offsetHrs);
        System.out.println("offsetMins: " + offsetMins);
        c.add(Calendar.HOUR_OF_DAY, (-offsetHrs));
        c.add(Calendar.MINUTE, (-offsetMins));

        System.out.println("GMT Time: " + c.getTime());

        return c;
    }
}

Related

  1. getCalendarUTC()
  2. getCalendarUTC(long timeMS)
  3. getLocalCalendarFromUTC(Calendar utc)
  4. getUTCCalendar()