Java code
Import java. text. SimpleDateFormat;
Import java. util. Calendar;
Public class DateAll {
Public static void main (String [] args) throws Exception {
// Current time
Calendar cal = Calendar. getInstance ();
// SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss ");
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss g e d f w W a e f ");
String mDateTime = formatter. format (cal. getTime ());
System. out. println (mDateTime );
// Date 1 year ago
Java. util. Date myDate = new java. util. Date ();
Long myTime = (myDate. getTime ()/1000)-60*60*24*365;
MyDate. setTime (myTime * 1000 );
String mDate = formatter. format (myDate );
System. out. println (mDate );
// Tomorrow's date
MyDate = new java. util. Date ();
MyTime = (myDate. getTime ()/1000) + 60*60*24;
MyDate. setTime (myTime * 1000 );
MDate = formatter. format (myDate );
System. out. println (mDate );
// Number of days between two times
SimpleDateFormat myFormatter = new SimpleDateFormat ("yyyy-MM-dd ");
Java. util. Date date = myFormatter. parse ("1883-10-10 ");
Java. util. Date mydate = myFormatter. parse ("1899-12-30 ");
Long day = (date. getTime ()-mydate. getTime ()/(24*60*60*1000 );
System. out. println (day );
// Add half an hour
SimpleDateFormat format = new SimpleDateFormat ("yyyy-MM-dd hh: mm: ss ");
Java. util. Date date1 = format. parse ("23:16:00 ");
Long Time = (date1.getTime ()/1000) + 60*30;
Date1.setTime (Time * 1000 );
String mydate1 = formatter. format (date1 );
System. out. println (mydate1 );
// Calculate the date of year, month, and week
SimpleDateFormat formatter2 = new SimpleDateFormat ("yyyy-mm f e ");
Java. util. Date date2 = formatter2.parse ("Friday 2003-05 ");
SimpleDateFormat formatter3 = new SimpleDateFormat ("yyyy-MM-dd ");
String mydate2 = formatter3.format (date2 );
System. out. println (mydate2 );
// The day of the week
Mydate = myFormatter. parse ("2007-11-9 ");
SimpleDateFormat formatter4 = new SimpleDateFormat ("E ");
String mydate3 = formatter4.format (mydate );
System. out. println (mydate3 );
}
}
Author: "sailei1"