Some ways to get the current date in Java

Source: Internet
Author: User
Tags dateformat locale

Remember something small. Gets the method for the current date/time in the format. C # 's ToString () Sure enough, I think the most loving way to format. Scripting languages, however, generally offer very handy methods, such as PHP, Perl, and Ruby, and so on, and JavaScript does not provide the format method, but writes itself a waste of nothing.

We all know C + + provides __date__ and __time__ macros, but these two macros are recorded at compile-time date and time, and can not be customized format, the discussion here is completely irrelevant ...

============================================================

DOS Batch File (on Windows NT):

Rely primarily on the command line's date/t and time/t commands to obtain the current system date and time, respectively.

Example:

2008-01-05 Saturday

11:20

Http://www.robvanderwoude.com/datetiment.html

============================================================

Java:

Java code

Import java.util.Date;
Import Java.util.Locale;
Import Java.text.DateFormat;

public class Greet {public
	static void Main (string[] args) {
		dateformat df
			= dateformat.getdatetimeinstance (
				dateformat.full, Dateformat.short, Locale.china);
		String message = Df.format (new Date ());
		SYSTEM.OUT.PRINTLN (message);
	}

Friday, January 4, 2008 07:54

Several related classes in Java are Java.util.date,java.util.time,java.util.calendar, Java.text.dateformat,java.text.simpledateformat and so on.

I'm not using a custom format in the example here, directly using the format specified by the Dateformat.full in the standard format.

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.