Java TimeZone String Parse parseCal(long time, TimeZone to)

Here you can find the source of parseCal(long time, TimeZone to)

Description

parse Cal

License

Open Source License

Declaration

private final static Calendar parseCal(long time, TimeZone to) 

Method Source Code

//package com.java2s;
/*/*from   w w w.  ja  v  a 2  s .co  m*/
 * Copyright ? 2012-2013 Visual Illusions Entertainment.
 *  
 * This file is part of VIUtils.
 *
 * VIUtils is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * VIUtils 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with VIUtils.
 * If not, see http://www.gnu.org/licenses/lgpl.html
 */

import java.util.Calendar;

import java.util.TimeZone;

public class Main {
    private final static Calendar parseCal(long time, TimeZone to) {
        Calendar calendar = Calendar.getInstance();
        TimeZone fromTimeZone = calendar.getTimeZone();
        TimeZone toTimeZone = to != null ? to : TimeZone.getTimeZone("GMT");

        calendar.setTimeZone(fromTimeZone);
        calendar.add(Calendar.MILLISECOND, fromTimeZone.getRawOffset() * -1);
        if (fromTimeZone.inDaylightTime(calendar.getTime())) {
            calendar.add(Calendar.MILLISECOND, calendar.getTimeZone().getDSTSavings() * -1);
        }

        calendar.add(Calendar.MILLISECOND, toTimeZone.getRawOffset());
        if (toTimeZone.inDaylightTime(calendar.getTime())) {
            calendar.add(Calendar.MILLISECOND, toTimeZone.getDSTSavings());
        }
        calendar.setTimeInMillis(time);
        return calendar;
    }
}

Related

  1. guessTimeZone(String timezoneOffset)
  2. parseDA(TimeZone tz, String s)
  3. parseTimeZoneId(String timeZoneId)
  4. parseTimeZoneString(String timeZoneString)
  5. parseTimeZoneString(String timeZoneString)