Java Date Format Change convertDateFormat(String date, SimpleDateFormat formatBefore, SimpleDateFormat formatAfter)

Here you can find the source of convertDateFormat(String date, SimpleDateFormat formatBefore, SimpleDateFormat formatAfter)

Description

convert Date Format

License

Open Source License

Declaration

public static String convertDateFormat(String date, SimpleDateFormat formatBefore, SimpleDateFormat formatAfter)
            throws ParseException 

Method Source Code


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

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

public class Main {
    public static String convertDateFormat(String date, SimpleDateFormat formatBefore, SimpleDateFormat formatAfter)
            throws ParseException {
        String convertDateStr = formatAfter.format(formatBefore.parse(date));
        return convertDateStr;
    }//from ww w  . jav a  2 s .  c  o m

    public static long parse(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return sdf.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static long parse(String date, String pattern) {

        SimpleDateFormat sdft = new SimpleDateFormat(pattern);
        try {
            return sdft.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }
}

Related

  1. convertDate(String dateIn, String fromDateFormat, String toDateFormat)
  2. convertDate(String inPattern, String outPattern, String date)
  3. convertDate(String inPattern, String outPattern, String date)
  4. convertDate(String str)
  5. convertDate(String value)
  6. convertDateFormat(String sourceDate, String sourceDateFormat, String destDateFormat)
  7. convertDateFormatByRawOffset(DateFormat formatter, int rawOffset, long milliSecond)
  8. convertDateFromInDayFormat(String stringDate, String hhmmss)
  9. convertDateFromTo(String stringDate, String patternToUse, TimeZone timezoneIn, TimeZone timezoneOut)