Java Tools class Date date class app

Source: Internet
Author: User
Tags dateformat float double

Directly on the code:

Package Test;import Java.text.dateformat;import Java.text.parseexception;import java.text.simpledateformat;import Java.util.date;public class Test {public static void main (string[] args) {Date date = new Date ();//Get system Current time System.out.pri NTLN (date);//print system current time long times = Date.gettime ();D ate d2 = new Date;//Use a defined date formatting tool class DateFormat df = dateformat.getd Ateinstance (Dateformat.default); System.out.println (Df.format (date));//convert string to date object try {date D3 = Df.parse ("15-03-04"); SYSTEM.OUT.PRINTLN (D3);} catch (ParseException e) {//TODO auto-generated catch Blocke.printstacktrace ();} Custom format format date and time//note: month mm minutes mm seconds: ss MS: Ssssimpledateformat SDF = new SimpleDateFormat ("Yyyy/mm/dd Hh:mm:ss:SSS"); System.out.println (Sdf.format (New Date ()));//Use System.currenttimemillis () to get the current time long time2 = System.currenttimemillis ();D ate d = new Date (time); System.out.println (d);/*calendar Calendar = Calendar.getinstance ();//system.out.println (calendar.tostring ());// Print the obtained calendarint year = Calendar.get (Calendar.yeaR);//Gets the year int month = Calendar.get (calendar.month);//Gets the month int day = calendar.get (calendar. Day_of_month);//Get the month to note that the month and the actual difference in the one month array subscript is 0 start//Indicates the month's Get and set field numbers. This is a calendar-specific value. The first month of the year in the Gregorian and Julian calendars is January, which is 0; the last one months depend on the number of months in the year. Int week = Calendar.get (Calendar.day_of_week);//Get DaySystem.out.println (year+ "-" +month+ "-" +day);//Print Date 2015-7-10/ /SYSTEM.OUT.PRINTLN (year); string[] months = {"January", "February", "March", "April", "May", "June", "July", "August"};//if you want to achieve printing the actual month can be achieved SYSTEM.OUT.PRINTLN (Months[month] );///0-11 so that you can print the correct month string[] weeks = {"", "Sunday", "Monday", "Tuesday"};//week of storage because it was developed by foreigners, so the first storage is Sunday So it's the same way as the month. SYSTEM.OUT.PRINTLN (Weeks[week]); System.out.println (Calendar.get (calendar.day_of_month)); System.out.println (Calendar.get (Calendar.hour_of_day));//24 hours String str = String.Format ("%d-%d month-%d Day", Year,month, day);//Gets the string of the format we want System.out.println (str);//%s string%c char%d int%f float Double the various types of SYSTEM.OUT.PRINTLN (String.Format ("%.2f", 10/3.0) to be used when formatting, *2015-7-108 month Monday10212015-July-10th 3.33 * */}} 
Hope to be useful to everyone

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Tools class Date date class app

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.