Android Timezone Change localDateTimeToServerTimeString( Date localDateTime, String serverTimeFormat)

Here you can find the source of localDateTimeToServerTimeString( Date localDateTime, String serverTimeFormat)

Description

local Date Time To Server Time String

License

Open Source License

Declaration

public static String localDateTimeToServerTimeString(
            Date localDateTime, String serverTimeFormat) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class Main {
    public static String localDateTimeToServerTimeString(
            Date localDateTime, String serverTimeFormat) {
        if (localDateTime == null) {
            return null;
        }//w ww .j a va 2s . c o m
        Calendar localCal = Calendar.getInstance(TimeZone
                .getTimeZone("GMT+00:00"));
        localCal.setTime(localDateTime);

        SimpleDateFormat sd = new SimpleDateFormat(serverTimeFormat);
        sd.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
        String serverDateString = sd.format(localCal.getTime());
        return serverDateString;
    }
}

Related

  1. serverTimeStringToLocalDateTime( String serverTimeString, String serverTimeFormat)
  2. getLocalCalendar()