是否可以在java中解析以下日期和时间?

时间:2013-11-19 07:18:40

标签: parsing datetime

我如何能够解析2013-12-20T00:45:00.000+05:30以分别获取日期和时间。这是IST。 我能够使用

获取日期
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
sdf.format(sdf1.parse(expirationDate)

但我不知道如何抽出时间。

2 个答案:

答案 0 :(得分:0)

    Timestamp timestamp = new Timestamp(System.currentTimeMillis());
    Date date = new Date(timestamp.getTime());

    // S is the millisecond
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy' 'HH:MM:ss:S");

    System.out.println(simpleDateFormat.format(timestamp));
    System.out.println(simpleDateFormat.format(date));

时间

   Date date = new Date();   // given date
   Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar      instance
   calendar.setTime(date);   // assigns calendar to given date 
   calendar.get(Calendar.HOUR_OF_DAY); // gets hour in 24h format
   calendar.get(Calendar.HOUR);        // gets hour in 12h format
   calendar.get(Calendar.MONTH);       // gets month number, NOTE this is zero base

答案 1 :(得分:0)

String expirationDate = "2013-12-20T00:45:00.000+05:30";
SimpleDateFormat string2DateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
SimpleDateFormat date2StringFormatter = new SimpleDateFormat("HH:mm:ss");
System.out.println(date2StringFormatter.format(string2DateFormatter.parse(expirationDate)));