"Java" About time

Source: Internet
Author: User

ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;Importjava.util.Date;/*** Created by Zay on 2016/12/9.*/ Public classTimetest { Public Static voidMain (string[] args) {//(1) Get the current timeSystem.out.println (NewDate ());        System.out.println (Calendar.getinstance ());        System.out.println (System.currenttimemillis ()); /*First output Fri Dec 00:28:05 CST*/        /*second output java.util.gregoriancalendar[time=1481214485061,arefieldsset=true,areallfieldsset=true,lenient=true, Zo Ne=sun.util.calendar.zoneinfo[id= "Asia/shanghai", Offset=28800000,dstsavings=0, usedaylight=false,transitions=19 , Lastrule=null],firstdayofweek=1, Minimaldaysinfirstweek=1,era=1,year=2016,month=11,week_of_year=50,week_of_ Month=2,day_of_month=9, Day_of_year=344,day_of_week=6,day_of_week_in_month=2,am_pm=0,hour=0,hour_of_day=0, Minute=28,second=5, millisecond=61,zone_offset=28800000,dst_offset=0]*/        /*The third one outputs the timestamp exactly to the millisecond level 1481214485061*/        //(2) Time formatSimpleDateFormat simple =NewSimpleDateFormat ("Yyyy-mm-dd"); System.out.println (Simple.format (NewDate ())); //(3) Common date arithmetic (plus minus according to calendar rules)Calendar calendar=calendar.getinstance ();//get a calendar using the default time zone and locale. Calendar.add (calendar.date,-2);//Gets the date of the first 10 days of the current dateSystem.out.println (Calendar.gettime ()); Calendar.set (2016,12,9);//sets the value of the Calendar field year, MONTH, and Day_of_month. //(4) Date, calendar, timestamp string three conversions//Get Date typeDate Date=calendar.gettime ();//Calendar, Date//get the type of calendarCalendar.settime (NewDate ());//date, Calendar//get time stamp stringCalendar.gettimeinmillis ();//Date -and timestamp string    }}

"Java" About time

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.