package com.java.myapp; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class MyClass { public static void main(String[] args) { String sDate = "2013-08-03 16:18:50"; DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date date = df.parse(sDate); Calendar c = Calendar.getInstance(); c.setTime(date); System.out.println("Full Date : " + date); System.out.println("Time : " + date.getTime()); System.out.println("Year : " + c.get(Calendar.YEAR)); int iMonth = c.get(Calendar.MONTH) + 1; System.out.println("Month : " + iMonth); System.out.println("Day : " + c.get(Calendar.DATE)); System.out.println("Hour : " + c.get(Calendar.HOUR_OF_DAY)); System.out.println("Minute : " + c.get(Calendar.MINUTE)); System.out.println("Second : " + c.get(Calendar.SECOND)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท