Java TimeZone toEpoch(Date dateTime, String timeZone)

Here you can find the source of toEpoch(Date dateTime, String timeZone)

Description

to Epoch

License

Open Source License

Declaration

public static Long toEpoch(Date dateTime, String timeZone) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static Long toEpoch(Date dateTime, String timeZone) {
        //Epoch of midnight in local time zone
        Calendar timeOffset = Calendar.getInstance(TimeZone
                .getTimeZone(timeZone));
        timeOffset.set(Calendar.MILLISECOND, 0);
        timeOffset.set(Calendar.SECOND, 0);
        timeOffset.set(Calendar.MINUTE, 0);
        timeOffset.set(Calendar.HOUR_OF_DAY, 0);

        long midnightOffSet = timeOffset.getTime().getTime();
        long localTimestamp = dateTime.getTime();

        return timeOffset == null ? null : midnightOffSet + localTimestamp;
    }/*from w w  w  .jav a  2  s. c o  m*/
}

Related

  1. midnight(Date date, TimeZone tz)
  2. monthOfYear(Date referenceDate, int month, TimeZone timeZone)
  3. normalizeDate(Date date, TimeZone timeZone)
  4. startOfNextDay(final Date date, final TimeZone timeZone)
  5. startOfYear(Date referenceDate, TimeZone timeZone)