Java Time Format getStringFormatFromDateTime(long pDateTime, String format)

Here you can find the source of getStringFormatFromDateTime(long pDateTime, String format)

Description

formats the supplied time in millis to the one specifiedin the format.

License

Apache License

Parameter

Parameter Description
pDateTime a parameter
format E.g. "dd-MM-yyyy HH:mm:ss Z"

Declaration

public static String getStringFormatFromDateTime(long pDateTime, String format) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private static final String serverTimezone = "Europe/Amsterdam";

    /**//from w ww  . j  ava2 s  .  com
     * formats the supplied time in millis to the one specifiedin the format.
     * @param pDateTime
     * @param format E.g. "dd-MM-yyyy HH:mm:ss Z"
     * @return
     */
    public static String getStringFormatFromDateTime(long pDateTime, String format) {
        format = format != null ? format : "dd-MM-yyyy HH:mm:ss Z";
        SimpleDateFormat dateFormat = new SimpleDateFormat(format, Locale.ENGLISH);
        dateFormat.setTimeZone(getServerTimeZone());
        return dateFormat.format(new Date(pDateTime));
    }

    public static TimeZone getServerTimeZone() {
        return TimeZone.getTimeZone(serverTimezone);
    }
}

Related

  1. getIntegerDateTime(Date date, String dateFormat)
  2. getShowTime(Date date, String format)
  3. getStartTimeFormatter()
  4. getStrDateByFormat(Date time, String format)
  5. getStrDateTime()
  6. getStringFromTime(Date time, String format)
  7. getSysDateTimeForFileName()
  8. getSysTimeYMDHMS2()
  9. getTime(@Nonnull String format, @Nonnull String date, @Nonnull String tz)