Java, JSP gets the current date of the year, month, day

Source: Internet
Author: User
Tags time in milliseconds

Java
 Package Com.ob;import Java.text.parseexception;import Java.text.simpledateformat;import java.util.Calendar;import Java.util.date;public class Datetest {public static void main (string[] args) throws ParseException {Calendar n        ow = Calendar.getinstance ();        System.out.println ("Year:" + Now.get (calendar.year));        System.out.println ("Month:" + (Now.get (calendar.month) + 1) + "");        System.out.println ("Day:" + now.get (calendar.day_of_month));        System.out.println ("Time:" + now.get (calendar.hour_of_day));        System.out.println ("min:" + now.get (Calendar.minute));        System.out.println ("seconds:" + now.get (Calendar.second));        System.out.println ("Current time milliseconds:" + now.gettimeinmillis ());        System.out.println (Now.gettime ());        Date d = new Date ();        System.out.println (d);        SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");        String datenowstr = Sdf.format (d);                SYSTEM.OUT.PRINTLN ("Formatted date:" + datenowstr); StRing str = "2012-1-13 17:26:33";        To the same format as the above SDF definition, Date today = Sdf.parse (str);    System.out.println ("string turns into Date:" + today); }}
Output Result:

Year: 2012
Month: 1
Day: 13
Hours: 17
Points: 28
Seconds: 19
Current time in milliseconds: 1326446899902
Fri Jan 17:28:19 CST 2012
Fri Jan 17:28:19 CST 2012
Date formatted: 2012-01-13 17:28:19
String converted to date: Fri Jan 17:26:33 CST 2012

Jsp
var date;        Var month;        var year;        var today = new Date ();        Year = Today.getfullyear ();        month = Today.getmonth () + 1;        Date = Today.getdate ();        Alert ("Time:" +year+ "" +month+ "" +date);

Java, JSP gets the current date of the year, month, day

Related Article

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.