Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Calendar;

public class Main {
    public static final int DST_START_DAY = 8;
    public static final int DST_START_MONTH = 3;
    public static final int DST_END_DAY = 1;
    public static final int DST_END_MONTH = 11;

    public static int getDaylightSavingsTimeOffset(long timeMs) {
        int dstOffset = 5; // default not daylight savings time

        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(timeMs);
        int day = c.get(Calendar.DATE);
        int month = c.get(Calendar.MONTH);
        if ((month > DST_START_MONTH && month < DST_END_MONTH) || (month == DST_START_MONTH && day >= DST_START_DAY)
                || (month == DST_END_MONTH && day <= DST_END_DAY)) {
            dstOffset = 4;
        }
        return dstOffset;
    }
}