Java Date to String dateToString(Date date)

Here you can find the source of dateToString(Date date)

Description

date To String

License

Apache License

Declaration

public static String dateToString(Date date) 

Method Source Code

//package com.java2s;
/*//  w  ww .  j  ava  2s. c om
 * Commons-Utils
 * Copyright (c) 2017.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 */

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.TimeZone;

public class Main {
    public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

    public static String dateToString(Date date, String pattern) {
        return dateToString(date, pattern, TimeZone.getDefault());
    }

    public static String dateToString(Date date) {
        return dateToString(date, YYYY_MM_DD_HH_MM_SS, TimeZone.getDefault());
    }

    public static String dateToString(Date date, String pattern, TimeZone timezone) {
        SimpleDateFormat dateFormat = null;
        if (null == pattern || "".equals(pattern)) {
            dateFormat = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        } else {
            dateFormat = new SimpleDateFormat(pattern);
        }
        dateFormat.setTimeZone(timezone);
        return dateFormat.format(date);
    }
}

Related

  1. dateToString(Date date)
  2. dateToString(Date date)
  3. dateToString(Date date)
  4. dateToString(Date date)
  5. dateToString(Date date)
  6. dateToString(Date date)
  7. dateToString(Date date)
  8. dateToString(Date date)
  9. dateToString(Date date)