Java
Package Com.ob;import Java.text.parseexception;import Java.text.simpledateformat;import java.util.Calendar;import Java.util.date;public class Datetest {public static void main (string[] args) throws ParseException {Calendar n ow = Calendar.getinstance (); System.out.println ("Year:" + Now.get (calendar.year)); System.out.println ("Month:" + (Now.get (calendar.month) + 1) + ""); System.out.println ("Day:" + now.get (calendar.day_of_month)); System.out.println ("Time:" + now.get (calendar.hour_of_day)); System.out.println ("min:" + now.get (Calendar.minute)); System.out.println ("seconds:" + now.get (Calendar.second)); System.out.println ("Current time milliseconds:" + now.gettimeinmillis ()); System.out.println (Now.gettime ()); Date d = new Date (); System.out.println (d); SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); String datenowstr = Sdf.format (d); SYSTEM.OUT.PRINTLN ("Formatted date:" + datenowstr); StRing str = "2012-1-13 17:26:33"; To the same format as the above SDF definition, Date today = Sdf.parse (str); System.out.println ("string turns into Date:" + today); }}
Output Result:
Year: 2012
Month: 1
Day: 13
Hours: 17
Points: 28
Seconds: 19
Current time in milliseconds: 1326446899902
Fri Jan 17:28:19 CST 2012
Fri Jan 17:28:19 CST 2012
Date formatted: 2012-01-13 17:28:19
String converted to date: Fri Jan 17:26:33 CST 2012
Jsp
var date; Var month; var year; var today = new Date (); Year = Today.getfullyear (); month = Today.getmonth () + 1; Date = Today.getdate (); Alert ("Time:" +year+ "" +month+ "" +date);
Java, JSP gets the current date of the year, month, day