Java examples for java.util:Calendar Format
yyyy-MM-dd HH:mm:ss String To Calendar
/*/* w w w . jav a 2 s . co m*/ * https://github.com/EngleVV/MyRepository * Copyright (c) 2004-2015 All Rights Reserved. */ //package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; public class Main { public static void main(String[] argv) throws Exception { String strDate = "java2s.com"; System.out.println(StringToCalendar(strDate)); } public static Calendar StringToCalendar(String strDate) { Calendar calendar = Calendar.getInstance(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss", Locale.CHINA); Date date = null; try { date = simpleDateFormat.parse(strDate); } catch (ParseException e) { e.printStackTrace(); } calendar.setTime(date); return calendar; } }