Java Timestamp Format format(Date date, String format)

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

Description

format

License

Open Source License

Declaration

public static String format(Date date, String format) 

Method Source Code


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

import java.sql.Timestamp;

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

public class Main {
    public static String format(Date date, String format) {
        SimpleDateFormat sf = new SimpleDateFormat(format);
        sf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        return sf.format(date);
    }/*from w ww .  ja v  a 2s. co m*/

    public static String format(Timestamp date, String format) {
        SimpleDateFormat sf = new SimpleDateFormat(format);
        sf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        return sf.format(date);
    }

    public static Date format(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        return c.getTime();
    }
}

Related

  1. compareTimstampStr(String timestamp1, String timestamp2, String format)
  2. decodeFileTimestamp(File file, Pattern filenamePattern, DateFormat dateFormat)
  3. format(BigDecimal data)
  4. format(Date aTs_Datetime)
  5. format(Date date)
  6. format(Date time, String pattern)
  7. format(Date timestamp)
  8. format(Date timestamp, String format)
  9. Format(DateFormat format, Timestamp time)