Example usage for java.util Calendar DST_OFFSET

List of usage examples for java.util Calendar DST_OFFSET

Introduction

In this page you can find the example usage for java.util Calendar DST_OFFSET.

Prototype

int DST_OFFSET

To view the source code for java.util Calendar DST_OFFSET.

Click Source Link

Document

Field number for get and set indicating the daylight saving offset in milliseconds.

Usage

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = new GregorianCalendar();
    System.out.println(cal.get(Calendar.DST_OFFSET));

}

From source file:MainClass.java

public static void main(String[] a) {
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(new Date());

    System.out.println("ERA: " + calendar.get(Calendar.ERA));
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
    System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
    System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
    System.out.println("DATE: " + calendar.get(Calendar.DATE));
    System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
    System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
    System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
    System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)));
    System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000)));
}

From source file:Main.java

public static int timeZoneOffset() {
    Calendar cal = Calendar.getInstance();
    int offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000);
    return offset;
}

From source file:Main.java

public static long addUTCTime(long timeMillis) {

    Calendar cal = Calendar.getInstance(Locale.getDefault());
    int zoneOffset = cal.get(java.util.Calendar.ZONE_OFFSET);
    int dstOffset = cal.get(java.util.Calendar.DST_OFFSET);

    timeMillis = timeMillis + zoneOffset + dstOffset;//        if (start.after(end)) {

    return timeMillis;
}

From source file:Main.java

public static Long GetUTCTime() {
    Calendar cal = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
    int zoneOffset = cal.get(Calendar.ZONE_OFFSET);
    int dstOffset = cal.get(Calendar.DST_OFFSET);
    cal.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset));
    return cal.getTimeInMillis();
}

From source file:Main.java

/**
 * This method is used to generate random number between given range.
 *///from  w w w. j  av a  2 s .co m
public static long getRandomNumberBetween() {
    Calendar rightNow = Calendar.getInstance();
    long offset = rightNow.get(Calendar.ZONE_OFFSET) + rightNow.get(Calendar.DST_OFFSET);
    long sinceMidnight = (rightNow.getTimeInMillis() + offset) % (24 * 60 * 60 * 1000);
    return sinceMidnight;
}

From source file:Main.java

private static TimeZone guessTimeZone(Calendar c, String country) {
    return TimeUtils.getTimeZone(c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET),
            c.get(Calendar.DST_OFFSET) != 0, c.getTimeInMillis(), country);
}

From source file:Main.java

public static String getGMTTimeString(long millisecond) {
    Calendar cal = Calendar.getInstance();
    int zoneOffsetTime = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
    long millisecondsUTC = millisecond - zoneOffsetTime;
    GMTTimeFormatter.setTimeZone(TimeZone.getDefault());
    String strGMTTime = GMTTimeFormatter.format(millisecondsUTC);
    return strGMTTime;
}

From source file:Main.java

@NonNull
public static synchronized String humanReadableDate(final long date, final boolean isUtc) {
    if (isUtc) {/*w  ww .  j ava 2s .c om*/
        final long offset = -(CALENDAR.get(Calendar.ZONE_OFFSET) + CALENDAR.get(Calendar.DST_OFFSET));
        return sFormat.format(date - offset);
    } else {
        return sFormat.format(date);
    }
}

From source file:org.exoplatform.poll.service.Utils.java

public static Calendar getGreenwichMeanTime() {
    Calendar calendar = GregorianCalendar.getInstance();
    calendar.setLenient(false);/*  ww  w.  j av a 2 s  . c om*/
    int gmtoffset = calendar.get(Calendar.DST_OFFSET) + calendar.get(Calendar.ZONE_OFFSET);
    calendar.setTimeInMillis(System.currentTimeMillis() - gmtoffset);
    return calendar;
}