Java Date to Time getTimeLocalWithoutDst(java.util.Date d)

Here you can find the source of getTimeLocalWithoutDst(java.util.Date d)

Description

Get the number of milliseconds since 1970-01-01 in the local timezone, but without daylight saving time into account.

License

Mozilla Public License

Parameter

Parameter Description
d the date

Return

the milliseconds

Declaration

public static long getTimeLocalWithoutDst(java.util.Date d) 

Method Source Code

//package com.java2s;
/*/*www  .java 2  s  .  c  om*/
 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
 * and the EPL 1.0 (http://h2database.com/html/license.html).
 * Initial Developer: H2 Group
 * Iso8601:
 * Initial Developer: Robert Rathsack (firstName dot lastName at gmx dot de)
 */

import java.util.Calendar;

import java.util.TimeZone;

public class Main {
    /**
     * The thread local. Can not override initialValue because this would result
     * in an inner class, which would not be garbage collected in a web
     * container, and prevent the class loader of H2 from being garbage
     * collected. Using a ThreadLocal on a system class like Calendar does not
     * have that problem, and while it is still a small memory leak, it is not a
     * class loader memory leak.
     */
    private static final ThreadLocal<Calendar> CACHED_CALENDAR = new ThreadLocal<Calendar>();
    /**
     * A cached instance of Calendar used when a timezone is specified.
     */
    private static final ThreadLocal<Calendar> CACHED_CALENDAR_NON_DEFAULT_TIMEZONE = new ThreadLocal<Calendar>();

    /**
     * Get the number of milliseconds since 1970-01-01 in the local timezone,
     * but without daylight saving time into account.
     *
     * @param d the date
     * @return the milliseconds
     */
    public static long getTimeLocalWithoutDst(java.util.Date d) {
        Calendar calendar = getCalendar();
        return d.getTime() + calendar.get(Calendar.ZONE_OFFSET);
    }

    /**
     * Get a calendar for the default timezone.
     *
     * @return a calendar instance. A cached instance is returned where possible
     */
    private static Calendar getCalendar() {
        Calendar c = CACHED_CALENDAR.get();
        if (c == null) {
            c = Calendar.getInstance();
            CACHED_CALENDAR.set(c);
        }
        c.clear();
        return c;
    }

    /**
     * Get a calendar for the given timezone.
     *
     * @param tz timezone for the calendar, is never null
     * @return a calendar instance. A cached instance is returned where possible
     */
    private static Calendar getCalendar(TimeZone tz) {
        Calendar c = CACHED_CALENDAR_NON_DEFAULT_TIMEZONE.get();
        if (c == null || !c.getTimeZone().equals(tz)) {
            c = Calendar.getInstance(tz);
            CACHED_CALENDAR_NON_DEFAULT_TIMEZONE.set(c);
        }
        c.clear();
        return c;
    }
}

Related

  1. getTimeImMillis(Date date)
  2. getTimeInSeconds(Date date)
  3. getTimeInterval(Date fromDate)
  4. getTimeIntervalMins(Date firstDate, Date lastDate)
  5. getTimeLocalWithoutDst(java.util.Date d)
  6. getTimeMargin(String dateTime)
  7. getTimeMax(Date date)
  8. getTimeOfDate(Date date)
  9. getTimeOnly(Date date)