You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As mentioned in the doc's date formatting section, we can specific a locale to affect the style of formatting. But can we also specific a timezone used when formatting?
// Maybe feasible solutionletdate=Date()// 2022-08-16 16:06:26 +0000letformattedInCurrentTimeZone= date.toFormat("yyyy-MM-dd HH:mm:ssZZZZZ")// current time zone, CST. 2022-08-17 00:06:26+0800letformattedInEST= date.toFormat("yyyy-MM-dd HH:mm:ssZZZZZ", timezone:.init("EST"))// 2022-08-16 12:06:26-0400
When formatting a Date, timezone is a required arguments since Date is a wrapper of timestamp which is an absolute value, however if we format the Date to a String, we need consider the timezone since a String representing a Date is a relative value. The locale and timezone could be different on a device. So we can not infer timezone from locale.
Thanks.
The text was updated successfully, but these errors were encountered:
As mentioned in the doc's date formatting section, we can specific a locale to affect the style of formatting. But can we also specific a timezone used when formatting?
When formatting a Date, timezone is a required arguments since Date is a wrapper of timestamp which is an absolute value, however if we format the Date to a String, we need consider the timezone since a String representing a Date is a relative value. The
locale
andtimezone
could be different on a device. So we can not infer timezone from locale.Thanks.
The text was updated successfully, but these errors were encountered: