Here you can find the source of toEpoch(Date dateTime, String timeZone)
public static Long toEpoch(Date dateTime, String timeZone)
//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*/ }