Skip to main content

String Methods


toLocalISOString()

Signature

toLocalISOString(): string

Return Type

string - ISO string with local offset

Notes

  • Similar to native toISOString() but preserves local timezone

Example

new Chronos('2025-01-01T00:00:00-05:00').toLocalISOString();
// "2025-01-01T00:00:00.000-05:00"

toISOString()

Signature

toISOString(): string

Return Type

string - Standard ISO 8601 string

Notes

  • Always returns UTC time
  • Consistent with native Date behavior

Example

new Chronos('2025-01-01T00:00:00-05:00').toISOString();
// "2025-01-01T05:00:00.000Z"

toLocaleString()

Signature

toLocaleString(
locale?: LocaleCode | Intl.Locale | (LocaleCode | Intl.Locale)[],
options?: Intl.DateTimeFormatOptions
): string

Parameters

  • locale: Locale string(s)
  • options: Intl.DateTimeFormat options

Return Type

string - Localized date string

Notes

  • Wrapper around native Date.toLocaleString()

Example

new Chronos('2025-01-15').toLocaleString('en-US', { 
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
// "Wednesday, January 15, 2025"

toString()

Signature

toString(): string

Return Type

string - Date string

Notes

  • Returns localized string representation
  • Includes timezone information when relevant

Example

new Chronos('2025-01-15').toString();
// "Sun Jan 15 2025 00:00:00 GMT-0500 (Eastern Standard Time)"

toJSON()

Signature

toJSON(): string

Return Type

string - ISO string

Notes

  • Used by JSON.stringify()
  • Same as toISOString()

Example

JSON.stringify({ date: new Chronos('2025-01-15') });
// '{"date":"2025-01-15T00:00:00.000Z"}'

inspect()

Signature

inspect(): string

Return Type

string - Debug-friendly string

Notes

  • Used by Node.js util.inspect
  • Includes Chronos prefix

Example

new Chronos('2025-01-15').inspect();
// "[Chronos 2025-01-15T00:00:00.000-05:00]"