Java Date to String dateToStringWithPattern(Date date, String pattern)

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

Description

date To String With Pattern

License

Open Source License

Declaration

public static String dateToStringWithPattern(Date date, String pattern) 

Method Source Code

//package com.java2s;
/*/*w ww  . j  a  v  a2s  .com*/
 * Copyright (C) 2010 Viettel Telecom. All rights reserved.
 * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static String dateToStringWithPattern(Date date, String pattern) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(pattern);
            return sdf.format(date);
        } catch (Exception e) {
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
            return sdf.format(date);
        }
    }
}

Related

  1. dateToStringShort(Date date)
  2. dateToStringTemporalCoverage(Date date)
  3. dateToStringVerbose(Date date)
  4. dateToStringWithFormat(Date dateToString, String dateFormat)
  5. dateToStringWithPattern(Date date, String pattern)
  6. dateToStringWithTime(Date date)
  7. dateToTimeString(Date date)
  8. dateToUTCDate(Date d)
  9. dateToUtcString(Date date)