Import java. util .*;
Int y, M, D, H, mm;
Calendar c = calendar. getinstance ();
Y = C. Get (calendar. year); // year
M = C. Get (calendar. month) + 1; // month
D = C. Get (calendar. day_of_month); // day
H = C. Get (calendar. hour); // hour (hour -- twelve hour; hour_of_day -- twenty-four hour)
Mm = C. Get (calendar. Minute); // minute
2:
Java. util. Date d = new java. util. Date ();
Java. Text. simpledateformat dformat = new java. Text. simpledateformat ("yyyy-mm-dd ");
String datetime = dformat. Format (d );
System. Out. println (datetime );
3:
Import java. util .*;
Import java. Text .*;
Date Now = new date ();
Dateformat defaultformat = dateformat. getdateinstance ();
Dateformat formatted format = dateformat. getdateinstance (dateformat. Short );
Dateformat mediumformat = dateformat. getdateinstance (dateformat. Medium );
Dateformat longformat = dateformat. getdateinstance (dateformat. Long );
Dateformat fullformat = dateformat. getdateinstance (dateformat. Full );
String defaultdate = defaultformat. Format (now );
String updated date = formatted format. Format (now );
String mediumdate = mediumformat. Format (now );
String longdate = longformat. Format (now );
String fulldate = fullformat. Format (now );
System. Out. println ("(default) Today:" + defaultdate );
System. Out. println ("(short) Today:" + latest date );
System. Out. println ("(medium) Today:" + mediumdate );
System. Out. println ("(long) Today:" + longdate );
System. Out. println ("(full) Today:" + fulldate );
4.
<%
Java. util. Date Now = new java. util. Date ();
Out. println (now );
%>
You can use substring () to intercept data.
Or use this string time = new simpledateformat ("yyyy-mm-dd"). Format (calendar. getinstance (). gettime );
5.
Date currenttime = new date ();
Simpledateformat formatter = new simpledateformat ("yyyy-mm-dd ");
String datestring = formatter. Format (currenttime );
The datastring format is.