Java TimeZone Format toAPITimeString(Date date, String format, String timeZone)

Here you can find the source of toAPITimeString(Date date, String format, String timeZone)

Description

to API Time String

License

CDDL license

Parameter

Parameter Description
date Date
format String
timeZone String

Return

String

Declaration

public static String toAPITimeString(Date date, String format,
        String timeZone) 

Method Source Code

//package com.java2s;
/*/*  www . j  a va 2 s . c o m*/
 Copyright (c) 2013 eBay, Inc.
 This program is licensed under the terms of the eBay Common Development and
 Distribution License (CDDL) Version 1.0 (the "License") and any subsequent  version 
 thereof released by eBay.  The then-current version of the License can be found 
 at http://www.opensource.org/licenses/cddl1.php and in the eBaySDKLicense file that 
 is under the eBay SDK ../docs directory.
 */

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

public class Main {
    static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
    static final String TIME_ZONE = "GMT";

    /**
     *
     * @param date Date
     * @param format String
     * @param timeZone String
     * @return String
     */
    public static String toAPITimeString(Date date, String format,
            String timeZone) {
        SimpleDateFormat dateFormatterAPI = null;
        dateFormatterAPI = new SimpleDateFormat(format);
        if (timeZone != null)
            dateFormatterAPI.setTimeZone(TimeZone.getTimeZone(timeZone));
        return dateFormatterAPI.format(date);
    }

    /**
     * Converts date to eBay API date string.
     * @param date Date
     * @return String
     */
    public static String toAPITimeString(Date date) {
        return toAPITimeString(date, DATE_FORMAT, TIME_ZONE);
    }
}

Related

  1. getUserToServerDateTimeString(TimeZone timeZone, int dateFormat, int timeFormat, String date)
  2. getZfgcTimeZoneDateFormat(String timezone)
  3. resolveTimeZone(SimpleDateFormat sdf, String timezone)
  4. String2Date(String date, String formatPattern, Locale locale, TimeZone timeZone)
  5. string2Timezone(String srcFormater, String srcDateTime, String dstFormater, String dstTimeZoneId)
  6. toTimeFormat(String timeFormat, TimeZone tz, Locale locale)