English
Date
About 514 wordsAbout 2 min
2026-01-09
Date
Date - Represents a date in YYYY-MM-DD format, enclosed in double quotes when used.
Summary
Define Date: Date date = "<YYYY-MM-DD>"
Example:
Date date = "2019-01-01"
```text
Date type methods:
Date.now(): Gets the current date (year, month, day)
Example:
```text
Date d = Date.now()
```text
date.withYear(`<Integer year>`): Sets the year of the date and returns a new date
Return type: Date
Example:
```text
date.withYear(2018) //Returns: 2018-01-01
```text
date.withMonth(`<Integer month>`): Sets the month of the date and returns a new date
Return type: Date
Example:
```text
date.withMonth(12) //Returns: 2019-12-01
```text
date.withDay(`<Integer day>`): Sets the day of the date and returns a new date
Return type: Date
Example:
```text
date.withDay(30) //Returns: 2019-01-30
```text
date.toTimestamp(): Converts date to timestamp
Return type: Long
Example:
```text
date.toTimestamp() //Returns: 1567958400000
```text
date.year: Gets the year from the date
Example:
```text
date.year //Returns: 2019
```text
date.month: Gets the month from the date
Example:
```text
date.month //Returns: 1
```text
date.day: Gets the day from the date
Example:
```text
date.day //Returns: 1
```text
date.dayOfWeek: Gets the day of week (1=Monday)
Example:
```text
date.dayOfWeek //Returns: 1 (Monday)
```text
date.weekOfYear: Gets the week number of the year
Example:
```text
date.weekOfYear //Returns: 1 (First week of the year)
```text
date.weekOfMonth: Gets the week number of the month
Example:
```text
date.weekOfMonth //Returns: 1 (First week of the month)
```text
date.dayOfYear: Gets the day number of the year
Example:
```text
date.dayOfYear //Returns: 1 (First day of the year)
```text
date.daysBetween(`<Date date>`): Returns the number of days between two dates
Example:
```text
Date date1 = "2020-01-02"
Date date2 = "2020-01-03"
date1.daysBetween(date2) //Returns: 2
```text
date.monthsBetween(`<Date date>`): Returns the number of months between two dates
Example:
```text
Date date1 = "2020-01-01"
Date date2 = "2020-03-03"
date1.monthsBetween(date2) //Returns: 2
```text
date.toStartOfMonth(): Returns the first day of the month
Example:
```text
Date date = "2020-01-20"
Date dateRetrun = date.toStartOfMonth() //Returns: 2020-01-01
```text
date.toStartOfWeek(): Returns the first day of the week (Monday)
Example:
```text
Date date = "2020-01-01"
Date dateRetrun = date.toStartOfWeek() //Returns: 2020-12-30
```text
Date.of(Long timestamp): Converts timestamp to date
Example:
```text
Long timestamp = 1618972431890
Date d = Date.of(timestamp)
```text
Date.of(`<String a>`): Converts string to date
Example:
```java
String a = "2020-01-01"
Date date = Date.of(a)
log.info("date:"+date)
```text
## Changelog
| Version | Date | Changes | Author |
| --- | --- | --- | --- |
| v1.0 | 2026-05-20 | Initial version | |
## Background
This document provides detailed information about the Date 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.