List of usage examples for java.util TimeZone getOffset
public int getOffset(long date)
From source file:Main.java
public static void main(String args[]) { TimeZone timezone = TimeZone.getTimeZone("Europe/Paris"); // checking offset value for date System.out.println("Offset value:" + timezone.getOffset(Calendar.ZONE_OFFSET)); }
From source file:com.jdo.CloudContactUtils.java
public static void main(String[] args) { // //ww w . ja va2 s .com // List<CloudContactNotification> lc=new ArrayList<CloudContactNotification>(); // CloudContactNotification a=new CloudContactNotification(); // a.setLastAccess(""+new Date().getTime()); // a.setText("tt"); // a.setUserName("dhaneesh"); // lc.add(a); // // System.out.println(JSONObject.wrap(lc)); // try { //Asia/Calcutta String[] allTimeZones = TimeZone.getAvailableIDs(); Date now = new Date(); for (int i = 0; i < allTimeZones.length; i++) { //System.out.println(allTimeZones[i]); TimeZone tz = TimeZone.getTimeZone(allTimeZones[i]); System.out.format("%s;%s; %f \n", allTimeZones[i], tz.getDisplayName(), (float) (tz.getOffset(now.getTime()) / 3600000.0)); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Main.java
public static long getLocalDateFromUTC(long utcDate) { //// TimeZone tz = TimeZone.getDefault(); long gmtOffser = tz.getOffset(utcDate); return utcDate - gmtOffser; }
From source file:Main.java
public static long adjustTimezoneOffset(long utcMillies) { TimeZone tz = TimeZone.getTimeZone("CET"); long offset = tz.getOffset(new Date().getTime()); return utcMillies + offset; }
From source file:Main.java
/** * // w w w . ja v a 2 s .co m * @return */ public static long getMillisGMT() { Calendar calendar = new GregorianCalendar(); TimeZone mTimeZone = calendar.getTimeZone(); int offset = mTimeZone.getOffset(System.currentTimeMillis()); return System.currentTimeMillis() - offset; }
From source file:Main.java
/** * Since all dates from the database are in UTC, we must convert the local date to the date in * UTC time. This function performs that conversion using the TimeZone offset. * * @param localDate The local datetime to convert to a UTC datetime, in milliseconds. * @return The UTC date (the local datetime + the TimeZone offset) in milliseconds. *//* w w w. j a v a 2 s .c o m*/ public static long getUTCDateFromLocal(long localDate) { TimeZone tz = TimeZone.getDefault(); long gmtOffset = tz.getOffset(localDate); return localDate + gmtOffset; }
From source file:Main.java
/** * Since all dates from the database are in UTC, we must convert the given date * (in UTC timezone) to the date in the local timezone. Ths function performs that conversion * using the TimeZone offset./* w w w .j a v a 2s .co m*/ * * @param utcDate The UTC datetime to convert to a local datetime, in milliseconds. * @return The local date (the UTC datetime - the TimeZone offset) in milliseconds. */ public static long getLocalDateFromUTC(long utcDate) { TimeZone tz = TimeZone.getDefault(); long gmtOffset = tz.getOffset(utcDate); return utcDate - gmtOffset; }
From source file:Main.java
public static Timestamp subtractTimeZoneOffset(Timestamp timestamp, TimeZone timeZone) { final long millisecondsToSubtract = Math.abs(timeZone.getOffset(timestamp.getTime())); return new Timestamp(timestamp.getTime() - millisecondsToSubtract); }
From source file:Main.java
public static long JD2mils(double jd, TimeZone tz) { long mils = JD2mils(jd); return mils - tz.getOffset(mils); }
From source file:Main.java
/** * Returns Timezone Offset From UTC in format {@code (+|i)HHMM} of specified * Timezone on specified date. If no date is specified, DST is considered * for the current date.// ww w. j a va2 s . c o m * * @param tz Timezone * @param date Date or {@code null} * @return Timezone Offset From UTC in format {@code (+|i)HHMM} */ public static String formatTimezoneOffsetFromUTC(TimeZone tz, Date date) { return appendZZZZZ(tz.getOffset(date == null ? System.currentTimeMillis() : date.getTime()), new StringBuilder(5)).toString(); }