Here you can find the source of calendarToGMTMillis(Calendar cal)
Parameter | Description |
---|---|
cal | The calendar object |
public static long calendarToGMTMillis(Calendar cal)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { /**/*from w w w.j a v a 2 s .co m*/ * Convert a calendar object to a long in the form of milliseconds since the * epoch of January 1, 1970. The time is converted to GMT if it is not * already in that timezone so that all times will be in a standard * timezone. * * @param cal * The calendar object * @return The time in milliseconds */ public static long calendarToGMTMillis(Calendar cal) { Date date = cal.getTime(); TimeZone tz = cal.getTimeZone(); int offset = tz.getOffset(date.getTime()); long time; if (offset != 0) { Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); gmtCal.setTime(date); gmtCal.add(Calendar.MILLISECOND, offset); time = gmtCal.getTimeInMillis(); } else { time = date.getTime(); } return time; } }