Java TimeZone Format getUserToServerDateTimeString(TimeZone timeZone, int dateFormat, int timeFormat, String date)

Here you can find the source of getUserToServerDateTimeString(TimeZone timeZone, int dateFormat, int timeFormat, String date)

Description

Gets the dateString attribute of the DateUtils object

License

Open Source License

Parameter

Parameter Description
date Description of the Parameter
timeZone Description of the Parameter
dateFormat Description of the Parameter
timeFormat Description of the Parameter

Return

The dateString value

Declaration

public static String getUserToServerDateTimeString(TimeZone timeZone, int dateFormat, int timeFormat,
        String date) 

Method Source Code

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

import java.text.DateFormat;

import java.util.Locale;
import java.util.TimeZone;

public class Main {
    /**/* w w  w .j a va2  s.  c om*/
     *  Gets the dateString attribute of the DateUtils object
     *
     * @param  date        Description of the Parameter
     * @param  timeZone    Description of the Parameter
     * @param  dateFormat  Description of the Parameter
     * @param  timeFormat  Description of the Parameter
     * @return             The dateString value
     */
    public static String getUserToServerDateTimeString(TimeZone timeZone, int dateFormat, int timeFormat,
            String date) {
        return getUserToServerDateTimeString(timeZone, dateFormat, timeFormat, date, Locale.getDefault());
    }

    /**
     *  Gets the userToServerDateTimeString attribute of the DateUtils class
     *
     * @param  timeZone    Description of the Parameter
     * @param  dateFormat  Description of the Parameter
     * @param  timeFormat  Description of the Parameter
     * @param  date        Description of the Parameter
     * @param  locale      Description of the Parameter
     * @return             The userToServerDateTimeString value
     */
    public static String getUserToServerDateTimeString(TimeZone timeZone, int dateFormat, int timeFormat,
            String date, Locale locale) {
        String convertedDate = null;
        try {
            DateFormat localeFormatter = DateFormat.getDateInstance(dateFormat, locale);
            if (timeZone != null) {
                localeFormatter.setTimeZone(timeZone);
            }
            DateFormat serverFormatter = DateFormat.getDateTimeInstance(dateFormat, timeFormat);
            //convertedDate = serverFormatter.format(localeFormatter.parse(date));
            convertedDate = serverFormatter.format(new java.util.Date(localeFormatter.parse(date).getTime()));
        } catch (Exception e) {
            if (date != null && !"".equals(date)) {
                System.err.println("EXCEPTION: DateUtils-> Timestamp " + e);
            }
        }
        return convertedDate;
    }
}

Related

  1. getSimpleDateFormat(TimeZone timeZone, String pattern)
  2. getString(Date dt, DateFormat df, TimeZone to)
  3. getTimeByZoneAndFormat(Date date, TimeZone zone, String format)
  4. getTimeWithFormat(String stringDate, String dateFormat, DateTimeZone timeZone, Locale locale)
  5. getTimezoneFormattedString(Date date, String timezone)
  6. getZfgcTimeZoneDateFormat(String timezone)
  7. resolveTimeZone(SimpleDateFormat sdf, String timezone)
  8. String2Date(String date, String formatPattern, Locale locale, TimeZone timeZone)
  9. string2Timezone(String srcFormater, String srcDateTime, String dstFormater, String dstTimeZoneId)