Several methods of obtaining system time in Java
2013-03-06 Hzhsongshu + pay attention to flowers (0)
Import Java.text.SimpleDateFormat;
Import Java.util.Calendar;
Method One:
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
String ly_time = Sdf.format (New java.util.Date ());
System.out.println ("Time is now:" +ly_time);
Result: The current time is: 2008-11-28 14:19:49
Method Two:
String ly_time = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (Calendar.getinstance (). GetTime ());
System.out.println ("Time is now:" +ly_time);
Result: The current time is: 2008-11-28 14:19:49
=======================
Java get current time Monday, April 14, 2008 10:11//This is a simple instance of getting the current time, as follows:
//--------------------------------------------
Import java.util.*;
Import java.text.*;
public class Nowstring {
public static void Main (string[] args) {
Date now = new Date ();
DateFormat d = dateformat.getdateinstance ();
String str = D.format (now);
System.out.println ("Today is" + str);
}
}
//--------------------------------------------
1, the pilot into two classes of java.util.*,java.text.*
2, add a simple sentence:
?
String date=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (Calendar.getinstance (). GetTime ());
Date is the time you get, the display format can be adjusted according to the format ("Yyyy-mm-dd HH:mm:ss"), if you want to take some more specific
?
Some date row data can view the calendar class of the API.
3, on the JSP page can be obtained by means of:
function PrintDate ()
{
var today=new Date ();
var day=today.getdate ();
var month=today.getmonth () +1;
var year=today.getfullyear (). toString ();
var box1=document.stats.intodate;
if ((MONTH/10) <1)
{
Month= ("0" +month). toString ();
}
if ((DAY/10) <1)
{
Day= ("0" +today.getdate ()). ToString ();
}
box1.value=year+ "-" +month+ "-" +day;
}
public void Time () {
int year=0;
int month=0;
int day=0;
Calendar c=calendar.getinstance ();//Get system Current date
Year=c.get (calendar.year);
Month=c.get (calendar.month) +1;//system date starting from 0
Day=c.get (Calendar.day_of_month);
System.out.println (year+ "" +month+ "" +day ");
}
public static void Main (String args[]) {
Newclass ne =new newclass ();
Ne.time ();
}
Get System Current Event Java