Theme Documentation
Date Utility
Date and time handling tool that automatically adapts to language settings
Component Examples
Basic Usage
The languageUtils.dayjs method provides a date handling tool that automatically adapts to the current language environment
Multilingual Support
languageUtils.dayjs automatically sets the correct locale based on the current language environment, with no manual configuration required
Date Formatting
Use the format method to display dates in specific formats, with support for localized formats
Plugin Features
Common plugins are preloaded, including relative time, date comparison and manipulation features
Usage
How to Use
Get languageUtils through useLanguage, then use its dayjs method to handle dates
Using in Components
Advantages of languageUtils.dayjs
- Automatically adapts to the current language environment, no need to manually set locale
- Follows system or user language preferences
- Globally consistent date formats and localization
- Simplifies code, reduces redundant code
Methods
Property | Description | Type | Default |
---|---|---|---|
format(formatStr) | Format date according to the specified format string | string | YYYY-MM-DD |
fromNow() | Display a text description relative to the current time, such as '3 hours ago' | string | - |
add(value, unit) | Add time, first parameter is value, second parameter is unit (e.g., 'day') | Dayjs | - |
subtract(value, unit) | Subtract time, first parameter is value, second parameter is unit (e.g., 'month') | Dayjs | - |
startOf(unit) | Return the start of a time period, e.g., startOf('month') returns the beginning of the month | Dayjs | - |
endOf(unit) | Return the end of a time period, e.g., endOf('day') returns the last moment of the day | Dayjs | - |
isBefore(date, unit) | Determine if a date is before another specified date | boolean | - |
isAfter(date, unit) | Determine if a date is after another specified date | boolean | - |
Common Formatting Options
Format | Description | Example |
---|---|---|
YYYY | Four-digit year | 2025 |
MM | Two-digit month (01-12) | 06 |
DD | Two-digit day of month (01-31) | 12 |
HH | Two-digit hour in 24-hour format (00-23) | 15 |
mm | Two-digit minutes (00-59) | 30 |
ss | Two-digit seconds (00-59) | 45 |
dddd | Day of week, localized display | 星期四 |
A | AM/PM, localized display | 下午 |
Best Practices
Use Language-Aware Date Handling
Always use languageUtils.dayjs instead of importing dayjs directly
Localized Format Patterns
Use predefined localized formats that automatically adapt to the current language
Usage in Templates
Use languageUtils.dayjs directly in templates without additional processing
Advanced Usage
Date Ranges and Batch Operations
Create date ranges and perform batch operations on dates