Java:String和Date.Timestamp之间的转 一.String与Date(java.util.Date)互转 1.1 String -> Date String dateStr = "2010/05/04 12:34:23"; Date date = new Date(); //注意format的格式要与日期String的格式相匹配 DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss&qu…
1. Calendar.add Example to add 1 year, 1 month, 1 day, 1 hour, 1 minute and 1 second to the current date. DateExample.java package com.mkyong.time; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java…
Java – How to get current date time 1. Code SnippetsFor java.util.Date, just create a new Date() DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); System.out.println(dateFormat.format(date)); //2016/11/…