How to convert String date to Java Calendar.
This can be done by some other way also, but I have done in the below format. Hope this is will help you.
Example :-
Input String Date - "20160829T23:59:59Z"
import java.text.SimpleDateFormat;Output :-
import java.util.Calendar;
import java.util.Date;
public class StringDateToCalendar {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
String string = "20160829T23:59:59Z";
String pattern = "yyyyMMdd'T'HH:mm:ss'Z'";
Date date = new SimpleDateFormat(pattern).parse(string);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
System.out.println("Calendar is :: "+ calendar.getTime());
}
}
Calendar is :: Mon Aug 29 23:59:59 AEST 2016
No comments:
Post a Comment