How to get the current system time in a JSP page

Source: Internet
Author: User
Tags date now dateformat

Originating From: http://hi.baidu.com/itfuck_/item/803662469cdf7baa61d7b945

1:

Import java.util.*;
int y,m,d,h,mm;

Calendar C = calendar.getinstance ();

y = C.get (calendar.year); Years

m = C.get (calendar.month) + 1; Month

D = C.get (Calendar.day_of_month); Day

h = c.get (Calendar.hour); Time 12-hour system

H2 = C.get (calendar.hour_of_day);//24-hour system

MM = C.get (Calendar.minute); Score of


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 Shortformat = 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 shortdate = Shortformat.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:" + shortdate);

System.out.println ("(MEDIUM) Today:" + mediumdate);

System.out.println ("(LONG) Today:" + longdate); System.out.println ("(Full) Today:" + fulldate);


4.
If it is only a year or so, it can be intercepted with substring (). or with 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 the 2007-03-08 type.

How to get the current system time in a JSP page

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.