@@ -18,13 +18,29 @@ import { DateTimeFormatter } from "./_common.ts";
18
18
* format(new Date(2019, 0, 20, 16, 34), "HH:mm MM-dd-yyyy"); // output : "16:34 01-20-2019"
19
19
* format(new Date(2019, 0, 20, 16, 34, 23, 123), "MM-dd-yyyy HH:mm:ss.SSS"); // output : "01-20-2019 16:34:23.123"
20
20
* format(new Date(2019, 0, 20), "'today:' yyyy-MM-dd"); // output : "today: 2019-01-20"
21
+ * format(new Date("2019-01-20T16:34:23:123-05:00"), "yyyy-MM-dd HH:mm:ss", { utc: true });
22
+ * // output : "2019-01-20 21:34:23"
21
23
* ```
22
24
*
23
- * @param date Date
24
- * @param formatString Format string
25
- * @return formatted date string
25
+ * @param date The date to be formatted.
26
+ * @param formatString The date time string format.
27
+ * @param options The options to customize the formatting of the date.
28
+ * @return The formatted date string.
26
29
*/
27
- export function format ( date : Date , formatString : string ) : string {
30
+ export function format (
31
+ date : Date ,
32
+ formatString : string ,
33
+ options : FormatOptions = { } ,
34
+ ) : string {
28
35
const formatter = new DateTimeFormatter ( formatString ) ;
29
- return formatter . format ( date ) ;
36
+ return formatter . format (
37
+ date ,
38
+ options . utc ? { timeZone : "UTC" } : undefined ,
39
+ ) ;
40
+ }
41
+
42
+ /** Options for {@linkcode format}. */
43
+ export interface FormatOptions {
44
+ /** Whether returns the formatted date in UTC instead of local time. */
45
+ utc ?: boolean ;
30
46
}
0 commit comments