Java Parse Date parseDateToStr(Date date)

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

Description

Parse Date to array of string

License

Open Source License

Parameter

Parameter Description
date : date to be converted

Return

array of string where String[0] = dd, String[1] = mm, String[2] = yyyy

Declaration

public static String[] parseDateToStr(Date date) 

Method Source Code

//package com.java2s;
/*//from  www  . ja v a 2 s. c  o m
 * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
 * Institute of Systems Science, National University of Singapore
 *
 * Copyright 2012 Team 4(Part-Time), ISS, NUS, Singapore. All rights reserved.
 * Use of this source code is subjected to the terms of the applicable license
 * agreement.
 *
 * -----------------------------------------------------------------
 * REVISION HISTORY
 * -----------------------------------------------------------------
 * DATE             AUTHOR          REVISION      DESCRIPTION
 * 10 March 2012    Chen Changfeng   0.1            Class creating
 *                                        
 *                                        
 *                                        
 *                                        
 * 
 */

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    /**
     * Parse Date to array of string
     *
     * @param    date : date to be converted
     * @return    array of string where String[0] = dd, String[1] = mm, String[2] = yyyy
     */
    public static String[] parseDateToStr(Date date) {
        String strFormat = "ddMMyyyy";
        SimpleDateFormat dateFormat = new SimpleDateFormat(strFormat);
        String[] arrDate = new String[3];
        String strDate = null;
        if (date == null)
            return arrDate;

        strDate = dateFormat.format(date);
        arrDate[0] = strDate.substring(0, 2);
        arrDate[1] = strDate.substring(2, 4);
        arrDate[2] = strDate.substring(4);
        return arrDate;
    }

    /**
     * Get the formatted string of the given date instance based on the
     * date format provided.
     * <p>
     * @param  date   The date that needs to be formatted.
     * @param  format The format to be applied to the date.
     * @return The formatted Date String.
     */
    public static String format(Date date, String format) {
        if (date == null || format == null)
            return null;

        SimpleDateFormat sdf = new SimpleDateFormat(format);

        return sdf.format(date);
    }
}

Related

  1. parseDateTimeFromString(String datetime)
  2. parseDateTimeHuman(String dateString)
  3. parseDateTimeString(final String date)
  4. parseDateTimeString(String dateTime)
  5. parseDateTimeString(String dateTimeString)
  6. parseDateToString(Date date, String format)
  7. parseDateToString(Date date, String pattern)
  8. parseDateToString(Date datetime)
  9. parseDateToString(final Date date, final String dateFormat, final String lang)