--- warning: This file is auto generated by `yarn web:inject`, do not edit by hand examples: - gmstrftime("%A", 1062462400) returns: - '''Tuesday''' dependencies: - php/datetime/strftime authors: original by: - Brett Zamir (https://brett-zamir.me) bugfixed by: - Brett Zamir (https://brett-zamir.me) input by: - Alex notes: [] parityVerified: - PHP 8.3 isTypescript: true type: function layout: function title: PHP's gmstrftime in TypeScript description: >- Here's what our current TypeScript equivalent to PHP's gmstrftime looks like. function: gmstrftime category: datetime language: php permalink: php/datetime/gmstrftime/ alias: - /functions/php/gmstrftime/ - /functions/datetime/gmstrftime/ - /php/gmstrftime/ - /functions/gmstrftime/ ---
{% codeblock lang:typescript %}import { strftime } from '../datetime/strftime.ts' export function gmstrftime(format: string, timestamp?: number | Date): string { // discuss at: https://locutus.io/php/gmstrftime/ // parity verified: PHP 8.3 // original by: Brett Zamir (https://brett-zamir.me) // input by: Alex // bugfixed by: Brett Zamir (https://brett-zamir.me) // example 1: gmstrftime("%A", 1062462400) // returns 1: 'Tuesday' const date = typeof timestamp === 'undefined' ? new Date() : timestamp instanceof Date ? new Date(timestamp) : new Date(timestamp * 1000) const utcTimestamp = Date.parse(date.toUTCString().slice(0, -4)) / 1000 return strftime(format, utcTimestamp) } {% endcodeblock %}