convert string into java.util.date format in java

后端 未结 3 984
闹比i
闹比i 2021-01-19 01:40

am having a string like this.

Thu Oct 07 11:31:50 IST 2010

I want to convert this into its exact date time format to store it in SQL.

相关标签:
3条回答
  • 2021-01-19 02:04

    Try this:

    SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
    

    For future reference read up on the SimpleDateFormat class: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

    0 讨论(0)
  • 2021-01-19 02:07

    Can't you do like below

       String str = "Thu Oct 07 11:31:50 IST 2010";
       SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd hh:mm:ss   'IST' yyyy");
       SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd");
       System.out.println(sdf2.format(sdf.parse(str)));
    
    0 讨论(0)
  • 2021-01-19 02:11

    Use this format -'EEE MMM dd HH:mm:ss z yyyy'

    Date date = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy")
                          .parse("Thu Oct 07 11:31:50 IST 2010");
    System.out.println(date);
    
    0 讨论(0)
提交回复
热议问题