import java.text.ParsePosition;
import java.text.SimpleDateFormat;
/**
来 自 时 代 J a v a 公 众 号 - N o w J a v a . c o m
**/
import java.util.Calendar;
import java.util.Date;
public class Main {
public static void main(String[] args){
String input = "2013-04-03 09:10:40.325";
// Prepare the pattern
String pattern = "yyyy-MM-dd HH:mm:ss.SSS" ;
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
// Parse the text into a Date object
Date dt = sdf.parse(input, new ParsePosition(0));
System.out.println(dt);
// Get the Calendar instance
Calendar cal = Calendar.getInstance();
//N o w J a v a . c o m 提供
// Set the time
cal.setTime(dt);
// Print time parts
System.out.println("Hour:" + cal.get(Calendar.HOUR));
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。