Here you can find the source of convertDateToServerTimeZoneDate(DateFormat formatter, String timeZoneName, long milliSecond)
Parameter | Description |
---|---|
formatter | a parameter |
timeZoneName | a parameter |
milliSecond | a parameter |
public static String convertDateToServerTimeZoneDate(DateFormat formatter, String timeZoneName, long milliSecond)
//package com.java2s; //License from project: Open Source License import java.text.DateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { /**//from w ww. j ava2s . c o m * This will convert server date/time to specified Time zone date/time and return the date in specified format. * * @param formatter * @param timeZoneName * @param milliSecond */ public static String convertDateToServerTimeZoneDate(DateFormat formatter, String timeZoneName, long milliSecond) { Long loginTimeZoneDate = milliSecond; if (timeZoneName != null) { loginTimeZoneDate = convertDateToServerTimeZoneDateInMilliSec(timeZoneName, milliSecond); } return formatter.format(new Date(loginTimeZoneDate)); } /** * This will convert server date/time to specified Time zone date/time and return the date in milliSecond. * * @param timeZoneName * @param milliSecond * @return */ public static long convertDateToServerTimeZoneDateInMilliSec(String timeZoneName, long milliSecond) { if (timeZoneName != null) { TimeZone loginTimeZone = TimeZone.getTimeZone(timeZoneName); Calendar calender = Calendar.getInstance(loginTimeZone); if (milliSecond != 0) { calender.setTimeInMillis(milliSecond); } calender.add(Calendar.MILLISECOND, -(calender.getTimeZone().getRawOffset())); calender.add(Calendar.MILLISECOND, -(calender.getTimeZone().getDSTSavings())); calender.add(Calendar.MILLISECOND, TimeZone.getDefault().getRawOffset()); return calender.getTimeInMillis(); } return milliSecond; } }