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

300px

Multilingual Support

languageUtils.dayjs automatically sets the correct locale based on the current language environment, with no manual configuration required

Switch Language
300px

Date Formatting

Use the format method to display dates in specific formats, with support for localized formats

300px

Plugin Features

Common plugins are preloaded, including relative time, date comparison and manipulation features

300px

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

PropertyDescriptionTypeDefault
format(formatStr)Format date according to the specified format stringstringYYYY-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 monthDayjs-
endOf(unit)Return the end of a time period, e.g., endOf('day') returns the last moment of the dayDayjs-
isBefore(date, unit)Determine if a date is before another specified dateboolean-
isAfter(date, unit)Determine if a date is after another specified dateboolean-

Common Formatting Options

FormatDescriptionExample
YYYYFour-digit year2025
MMTwo-digit month (01-12)06
DDTwo-digit day of month (01-31)12
HHTwo-digit hour in 24-hour format (00-23)15
mmTwo-digit minutes (00-59)30
ssTwo-digit seconds (00-59)45
ddddDay of week, localized display星期四
AAM/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

Design Empowers, Innovation Unlimited