简体   繁体   English

无论时区如何,都显示为从那一刻起的日期

[英]Show as it is date from moment irrespective of time zone

I did console logging for moment object and its showing following results:我对 object 进行了控制台日志记录,并显示以下结果: 时刻对象的控制台日志

Moment {_isAMomentObject: true, _i: "/Date(1616070600000+0530)/", _isUTC: true, _pf: {…}, _locale: Locale, …}
_d: Thu Mar 18 2021 18:00:00 GMT+0530 (India Standard Time) {}

I want to show on UI is Thu Mar 18 2021 18:00:00 irrespective of user location and his/her current time zone.我想在 UI 上显示Thu Mar 18 2021 18:00:00 ,无论用户位置和他/她当前的时区如何。

I tried something like this我尝试过这样的事情

console.log(moment.utc(this.response_d));
    this.res_d = moment.utc(this.response_d).utcOffset('+5:30').format('YYYY-MM-DD h:mm:ss A');

and in html file as:在 html 文件中为:

<div class="ItemBox QuantityGrid MiniGrid responseDate">
       Response due date :     
        {{ res_d }}  
    </div>

but it shows Response due date: 2021-03-18 12:30:00 PM但它显示Response due date: 2021-03-18 12:30:00 PM


I don't have anough details about your response_data_string how it is got in your TypeScript controller.. 我没有关于您的 response_data_string 的详细信息,它是如何在您的 TypeScript controller 中获得的。
But I recommand you to use [angular date pipe](https://angular.io/api/common/DatePipe) instead of using moment instance inside your html template. 但我建议您使用 [角度日期管道](https://angular.io/api/common/DatePipe) 而不是在 html 模板中使用时刻实例。
But if you want, did you tried to force formatting your moment instance like this: 但是,如果您愿意,您是否尝试像这样强制格式化您的时刻实例:
 {{ moment(response_date_string,'YYYY-MM-DD HH:mm:ss').toDate()|date }}

if this is not working, you can debug your response_date_string variable by using {{response_date_string|json}}如果这不起作用,您可以使用{{response_date_string|json}}调试您的response_date_string变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM