Java Timestamp from convertToTimeStamp(Timestamp timestamp, String format, TimeZone timeZone)

Here you can find the source of convertToTimeStamp(Timestamp timestamp, String format, TimeZone timeZone)

Description

This method converts a given time stamp in a specified date format and as per specified time zone

License

Open Source License

Parameter

Parameter Description
timestamp input time stamp
format input date format as per which output is required
timeZone input time zone in which time stamp needs to be converted

Declaration

public static String convertToTimeStamp(Timestamp timestamp, String format, TimeZone timeZone) 

Method Source Code


//package com.java2s;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

import java.util.TimeZone;

public class Main {
    /**//from  w  w w  . j a va2s  .com
     * This method converts a given time stamp in a specified date format and as per specified time zone
     * @param timestamp input time stamp
     * @param format input date format as per which output is required
     * @param timeZone input time zone in which time stamp needs to be converted
     * @return
     */
    public static String convertToTimeStamp(Timestamp timestamp, String format, TimeZone timeZone) {
        String strTimeStamp = "";
        if (timestamp == null)
            return strTimeStamp;
        final SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        dateFormat.setTimeZone(timeZone);
        strTimeStamp = dateFormat.format(timestamp);
        return strTimeStamp;
    }
}

Related

  1. convertToTimestamp(Date aJavaDate)
  2. convertToTimestamp(java.util.Date date)
  3. convertToTimestamp(String dateData)
  4. convertToTimestamp(String dateString, String pattern)
  5. convertToTimestamp(String s)
  6. convertToTimestampDate(Date date)
  7. convertToTimestampHMS(String dateData)
  8. getFirstTimeOfDay(Calendar calendar)
  9. timestampFromCalendar(Calendar calendar)