Java Date to String dateToStr(Date date, String format)

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

Description

date To Str

License

Open Source License

Declaration

public static String dateToStr(Date date, String format) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.TimeZone;

public class Main {

    public static String dateToStr(Date date, String format) {
        String _timeZone = System.getProperty("user.timezone");
        TimeZone timeZone = null;
        if (_timeZone == null || "".equals(_timeZone)
                || "UTC".equals(_timeZone)) {
            timeZone = TimeZone.getDefault();
        } else {//  ww w.j  a  va2  s  . co m
            timeZone = TimeZone.getTimeZone("Asia/Shanghai");
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        dateFormat.setTimeZone(timeZone);
        return dateFormat.format(date);
    }
}

Related

  1. dateToStr(Date date)
  2. dateToStr(Date date)
  3. dateToStr(Date date)
  4. dateToStr(Date date)
  5. dateToStr(Date date, int type)
  6. dateToStr(Date date, String format)
  7. dateToStr(Date date, String formatstr)
  8. dateToStr(Date date, String formatType)
  9. dateToStr(Date source)