new SimpleDateFormat(String pattern, Locale locale) : SimpleDateFormat « java.text « Java by API






new SimpleDateFormat(String pattern, Locale locale)

 

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class Main {

  public static Calendar parseTimestamp(String timestamp) throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss", Locale.US);
    Date d = sdf.parse(timestamp);
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);
    return cal;
  }

  public static void main(String a[]) throws Exception {
    String timestampToParse = "24-Feb-2009 17:39:35";
    System.out.println("Timestamp : " + timestampToParse);

    SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    System.out.println("Calendar : " + sdf.format(parseTimestamp(timestampToParse).getTime()));
  }

}

   
  








Related examples in the same category

1.new SimpleDateFormat('hh:mm:ss')
2.new SimpleDateFormat('dd MMM yyyy hh:mm:ss zzz')
3.new SimpleDateFormat('E MMM dd yyyy')
4.new SimpleDateFormat('yyyy-MM-dd')
5.SimpleDateFormat: applyPattern(String pattern)
6.SimpleDateFormat: format(Date d)
7.SimpleDateFormat: parse(String text, ParsePosition pos)
8.SimpleDateFormat: setDateFormatSymbols(DateFormatSymbols newFormatSymbols)