1dateutil (time tool class) - current time and current timestamp

Technical work should be rewarded
 follow+Click three times (like, comment, collect) and watch again to form a good habit

hutool actual combat (take you to master various tools inside) directory

Purpose: get the current time

Usage scenario

Current time, multiple ways to obtain the current timestamp

Project reference

The basis of this blog post: hutool-5.6.5 version source code

        <dependency>
			<groupId>cn.hutool</groupId>
			<artifactId>hutool-core</artifactId>
			<version>5.6.5</version>
		</dependency>

Method summary

methoddescribe
cn.hutool.core.date.DateUtil.date()
Current time, converted to {@ link DateTime} object
cn.hutool.core.date.DateUtil.dateSecond()
Current time, converted to {@ link DateTime} object, ignoring milliseconds
cn.hutool.core.date.DateUtil.current()
Timestamp of the current time
cn.hutool.core.date.DateUtil.currentSeconds()
Timestamp of the current time (seconds)
cn.hutool.core.date.DateUtil.now()
Current time, format yyyy MM DD HH: mm: SS
cn.hutool.core.date.DateUtil.today()
Current date, format yyyy MM DD

Method details

Method name: CN hutool. core. date. DateUtil. date()

Method description

Current time, converted to {@ link DateTime} object

Supported version and above

Parameter Description:

Parameter namedescribe

Return value:

current time

Reference case:

		// current time 
		Date date = DateUtil.date();
		Assert.assertNotNull(date);

Source code analysis:

Link: to be added

Method details

Method name: CN hutool. core. date. DateUtil. dateSecond()

Method description

Current time, converted to {@ link DateTime} object, ignoring milliseconds

Supported version and above

4.6.2

Parameter Description:

Parameter namedescribe

Return value:

current time

Reference case:

		//The millisecond portion of the current time is ignored
		Date date4 = DateUtil.dateSecond();
		Assert.assertNotNull(date4);

Source code analysis:

Link: to be added

Method details

Method name: CN hutool. core. date. DateUtil. current()

Method description

Timestamp of the current time

Supported version and above

Parameter Description:

Parameter namedescribe

Return value:

time

Reference case:

        long current = DateUtil.current();
		String currentStr = String.valueOf(current);
		Assert.assertEquals(13, currentStr.length());

		long currentNano = DateUtil.current();
		String currentNanoStr = String.valueOf(currentNano);
		Assert.assertNotNull(currentNanoStr);

Source code analysis:

Link: to be added

Method details

Method name: CN hutool. core. date. DateUtil. currentSeconds()

Method description

Timestamp of the current time (seconds)

Supported version and above

4.0.0

Parameter Description:

Parameter namedescribe

Return value:

Current time seconds

Reference case:

		//Timestamp of the current time (seconds)
		long dateSeconds = DateUtil.currentSeconds();
		System.out.println(dateSeconds);
		Assert.assertNotNull(dateSeconds);

Source code analysis:

Link: to be added

Method details

Method name: CN hutool. core. date. DateUtil. now()

Method description

Current time, format yyyy MM DD HH: mm: SS

Supported version and above

Parameter Description:

Parameter namedescribe

Return value:

The standard form string of the current time

Reference case:

        // Current date string, format: yyyy MM DD HH: mm: SS
		String now = DateUtil.now();
		Assert.assertNotNull(now);

Source code analysis:

Link: to be added

Method details

Method name: CN hutool. core. date. DateUtil. today()

Method description

Current date, format yyyy MM DD

Supported version and above

Parameter Description:

Parameter namedescribe

Return value:

The standard form string of the current date

Reference case:

		// Current date string, format: yyyy MM DD
		String today = DateUtil.today();
		Assert.assertNotNull(today);

Source code analysis:

Link: to be added

Keywords: Java hutool

Added by nmal on Tue, 08 Feb 2022 14:55:35 +0200