String date into Epoch time

后端 未结 4 1930
闹比i
闹比i 2020-12-07 06:44

I am little bit confused in dates. I am currently working on the weather app and everything works fine .. I just wanna handle this type of format into my own desirable forma

4条回答
  •  悲哀的现实
    2020-12-07 07:20

    Use a SimpleDateFormat instance to parse the string into a Date object:

    DateFormat parser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
    Date date = parser.parse("2017-09-10T18:35:00+05:00");
    

    And then use another SimpleDateFormat to display it:

    DateFormat format = new SimpleDateFormat("EEE, dd MMMMM h:mm a");
    String formatted = format.format(date); // Sun, 10 September 1:35 PM
    

提交回复
热议问题