Java Date Convert convertDateToServerTimeZoneDateInMilliSec(String timeZoneName, long milliSecond)

Here you can find the source of convertDateToServerTimeZoneDateInMilliSec(String timeZoneName, long milliSecond)

Description

This will convert server date/time to specified Time zone date/time and return the date in milliSecond.

License

Open Source License

Parameter

Parameter Description
timeZoneName a parameter
milliSecond a parameter

Declaration

public static long convertDateToServerTimeZoneDateInMilliSec(String timeZoneName, long milliSecond) 

Method Source Code

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

import java.util.Calendar;

import java.util.TimeZone;

public class Main {
    /**/* w w  w  . ja  v  a2 s .  co  m*/
     * 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;
    }
}

Related

  1. convertDateTimeToSysTime(String sDateTime)
  2. ConvertDateToAge(String date)
  3. convertDateToDoubleTime(Date time)
  4. convertDateToInt(final Date date)
  5. convertDateToLong(int year, int month, int day, int hour, int minute, int second)
  6. convertDateToTimeStamp(Date date)
  7. convertDateToUTC(Date date)
  8. convertDateToWindowsTime(Date javaDate)
  9. convertDateValueToMillis(TimeZone tz, long dateValue)