English
DateTime
About 512 wordsAbout 2 min
2026-01-09
DateTime
Date - A concrete date type formatted as YYYY-MM-DD hh:mm, enclosed in quotes when used.
Summary
Define Date: DateTime dateTime = "<YYYY-MM-DD hh:mm>"
Example:
DateTime dateTime = "2019-01-01 12:00"
```text
DateTime type methods:
- DateTime.now(): Gets the current year, month, day, hour and minute
Example:
```text
DateTime d = DateTime.now()
```text
- dateTime.withYear(`<Integer year>`): Sets the year of the date and returns a new date
Return type: DateTime
Example:
```text
dateTime.withYear(2018) //Returns: 2018-01-01 12:00
```text
- dateTime.withMonth(`<Integer month>`): Sets the month of the date and returns a new date
Return type: DateTime
Example:
```text
dateTime.withMonth(12) //Returns: 2019-12-01 12:00
```text
- dateTime.withDay(`<Integer day>`): Sets the day of the date and returns a new date
Return type: DateTime
Example:
```text
dateTime.withDay(30) //Returns: 2019-01-30 12:00
```text
- dateTime.withHour(`<Integer hour>`): Sets the hour of the date and returns a new date
Return type: DateTime
Example:
```text
dateTime.withHour(13) //Returns: 2019-01-01 13:00
```text
- dateTime.withMinute(`<Integer day>`): Sets the minute of the date and returns a new date
Return type: DateTime
Example:
```text
dateTime.withMinute(30) //Returns: 2019-01-01 12:30
```text
- dateTime.toTimestamp(): Converts date to timestamp
Return type: Long
Example:
```text
dateTime.toTimestamp() //Returns: 1568001600000
```text
- dateTime.year: Gets the year from the date
Example:
```text
dateTime.year //Returns: 2019
```text
- dateTime.month: Gets the month from the date
Example:
```text
dateTime.month //Returns: 1
```text
- dateTime.day: Gets the day from the date
Example:
```text
dateTime.day //Returns: 1
```text
- dateTime.hour: Gets the hour from the date
Example:
```text
dateTime.hour //Returns: 12
```text
- dateTime.minute: Gets the minute from the date
Example:
```text
dateTime.minute //Returns: 0
```text
- dateTime.dayOfWeek: Gets the day of week for current date
Example:
```text
dateTime.dayOfWeek //Returns: 1(Monday)
```text
- dateTime.weekOfYear: Gets the week number of year for current date
Example:
```text
dateTime.weekOfYear //Returns: 1(First week of year)
```text
- dateTime.weekOfMonth: Gets the week number of month for current date
Example:
```text
dateTime.weekOfMonth //Returns: 1(First week of month)
```text
- dateTime.toDate: Converts DateTime to Date
Example:
```text
DateTime dateTime = "2019-01-01 12:00"
Date date = dateTime.toDate()
log.info(date)
```text
- DateTime.of(Long timestamp): Converts timestamp to DateTime
```text
Long timestamp = 1618972431890
DateTime d1 = DateTime.of(timestamp)
```text
- DateTime.of(`<String a>`): Converts string to date
Example:
```java
String b = "2020-01-01 00:00"
DateTime dateTime = DateTime.of(b)
log.info("dateTime"+ dateTime)
```text
## Changelog
| Version | Date | Changes | Author |
| --- | --- | --- | --- |
| v1.0 | 2026-05-20 | Initial version | |
## Background
This document provides detailed information about the DateTime API functionality and usage, helping developers integrate relevant capabilities.
## Applicable Scenarios
Specific applicable scenarios are determined by actual business needs. Developers can select the appropriate API for integration as required.
## Prerequisites
- Access to Fxiaoke Open Platform
- Application authorization and configuration completed
- Basic knowledge of relevant business domain
## Steps
Please refer to the detailed instructions for each API.
## Notes
- Ensure prerequisites are met before calling APIs
- Pay attention to API call frequency limits
- Refer to error code documentation for exception handling
> **Compatibility:** This version currently has no deprecated or compatibility notes.