Use this skill when handling dates and times in the application. Ensures consistent UTC storage and JST display patterns across backend and frontend code.
Use this skill when handling dates and times in API routes, database operations, or frontend display.
UTC Storage + Frontend JST Conversion
| Layer | Format | Example |
|---|---|---|
| Database | UTC | 2025-01-14T22:43:00Z |
| Frontend Display | JST | 07:43 |
Always save timestamps in UTC using toISOString().
// GOOD
const record = {
checked_in_at: new Date().toISOString() // "2025-01-14T22:43:00Z"
}
// DB column type: TIMESTAMP WITH TIME ZONE
Always specify timeZone: 'Asia/Tokyo' when displaying.
// GOOD
new Date(utcString).toLocaleTimeString('ja-JP', {
hour: '2-digit',
minute: '2-digit',
timeZone: 'Asia/Tokyo'
})
Use utility functions from lib/utils/timezone.ts.
import { getCurrentDateJST, getCurrentTimeJST } from '@/lib/utils/timezone'
const today = getCurrentDateJST() // "2025-01-15"
const now = getCurrentTimeJST() // "07:43"
new Date().toISOString() for database storagetimeZone: 'Asia/Tokyo' for displaygetCurrentDateJST() / getCurrentTimeJST() for current date/timeTIMESTAMP WITH TIME ZONE column typenew Date().toISOString().split('T')[0] for "today's date"
Available in lib/utils/timezone.ts:
| Function | Description | Return Example |
|---|---|---|
formatTimeJST(isoString) | Convert UTC string to JST time | "07:43" |
getCurrentDateJST() | Get current JST date | "2025-01-15" |
getCurrentTimeJST() | Get current JST time | "07:43" |
lib/utils/timezone.ts - Utility function implementationsdocs/03_database.md - Database schema definitions