2013-11-19 3 views
0

Как я могу разобрать 2013-12-20T00:45:00.000+05:30, чтобы получить дату и время по отдельности. Это находится в IST. я был в состоянии получить дату с помощьюВозможно ли разобрать следующие даты и времени в java?

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

, но я не знаю, как получить время.

ответ

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 
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))); 
Смежные вопросы