使用luxon的反应性午餐时间格式

发布于 2025-02-06 09:26:27 字数 493 浏览 2 评论 0原文

我正在尝试用luxonjs替换Momentjs,该luxonjs用反应性形式的Mat-datepicker使用,最初我使用ISO格式加载了datepicker字段

'2022-05-10T10:34:31.311-04:00'

,我在Luxon格式下使用该值来保存值

dateTime.fromiso( this.form?.get('date')?value ).toisodate();

datetime.fromiso(this.form?get('date')?value) .plus({day:1}) .toisodate();

当我选择其他日期时,日期格式与我的原始格式不同

太阳5月1日2022 00:00:00 GMT-0400(东部日光时间)

如何使用Luxon将此格式更改为ISO

I'm trying to replace momentjs with luxonjs which is used in mat-datepicker of a reactive form, initially I'm loading the datepicker field with ISO format

'2022-05-10T10:34:31.311-04:00'

for which I used below luxon formatting to save the values

DateTime.fromISO(
this.form?.get('date')?.value
).toISODate();

DateTime.fromISO(this.form?.get('date')?.value)
.plus({ day: 1 })
.toISODate();

When I select different date, the date format is different from my original

Sun May 01 2022 00:00:00 GMT-0400 (Eastern Daylight Time)

How to change this format to ISO using luxon

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苯莒 2025-02-13 09:26:28

我通过使用Angular DatePipe将反应性形式日期值转换为ISO格式,通过解决方法解决了这个问题

let date = new DatePipe('en-US').transform(
  this.form?.get('date')?.value,
  'yyyy-MM-ddThh:mm:ss'
); 
date = DateTime.fromISO(date).plus({ day: 1 }).toISODate();

I solved this issue with a workaround by converting the reactive form date value to ISO format using angular DatePipe

let date = new DatePipe('en-US').transform(
  this.form?.get('date')?.value,
  'yyyy-MM-ddThh:mm:ss'
); 
date = DateTime.fromISO(date).plus({ day: 1 }).toISODate();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文