Get System Current Event Java

Source: Internet
Author: User
Tags date now dateformat

  

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.