Java Date Format Change convertDateStringToString(String dateString, String format)

Here you can find the source of convertDateStringToString(String dateString, String format)

Description

convert Date String To String

License

Open Source License

Declaration

public static String convertDateStringToString(String dateString, String format) 

Method Source Code


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

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static String convertDateStringToString(String dateString, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Date date = null;// w  ww . j  a va  2 s.  co  m
        String dateStr = "";
        try {
            date = sdf.parse(dateString);
            dateStr = convertDateToStringByFormat(date);
        } catch (ParseException e) {

            e.printStackTrace();
        }
        return dateStr;

    }

    public static String convertDateToStringByFormat(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }

    public static String convertDateToStringByFormat(Date date, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
}

Related

  1. convertDateFormat(String date, SimpleDateFormat formatBefore, SimpleDateFormat formatAfter)
  2. convertDateFormat(String sourceDate, String sourceDateFormat, String destDateFormat)
  3. convertDateFormatByRawOffset(DateFormat formatter, int rawOffset, long milliSecond)
  4. convertDateFromInDayFormat(String stringDate, String hhmmss)
  5. convertDateFromTo(String stringDate, String patternToUse, TimeZone timezoneIn, TimeZone timezoneOut)
  6. convertDateStringToString(String strDate, String currentFormat, String parseFormat)
  7. convertDatetimeFormat(Date tar_date, String date_format)
  8. convertIso8601FormatToArsTime(String timeString)
  9. convertIso8601FormatToArsTimeOfDay(String timeOfDayString)