toisostring

convert string to ISO date time in nodejs

穿精又带淫゛_ 提交于 2021-01-29 12:29:41
问题 Convert this date into ISO format in nodejs created_at="September 17th 2019, 16:50:17.000"; let new_time = new Date(created_at); created_at = new_time.toISOString(); console.log(created_at); Output: Invalid Date Exacting output is in ISO format. like this 2011-10-05T14:48:00.000Z 回答1: Moment.js is a library which you can use to get the output and do some advanced operations with date and timezones. Below is the code to get expected output. var moment = require('moment') created_at="September

Get the local date instead of UTC

橙三吉。 提交于 2020-06-29 04:19:05
问题 The following script calculates me next Friday and next Sunday date. The problem : the use of .toISOString uses UTC time. I need to change with something that outputs local time. I'm very new to javascript so I can't find the right property to use instead of .toIsostring. What should I do ? function nextWeekdayDate(date, day_in_week) { var ret = new Date(date || new Date()); ret.setDate(ret.getDate() + (day_in_week - 1 - ret.getDay() + 7) % 7 + 1); return ret; } let nextFriday =

Get the local date instead of UTC

纵饮孤独 提交于 2020-06-09 05:26:07
问题 The following script calculates me next Friday and next Sunday date. The problem : the use of .toISOString uses UTC time. I need to change with something that outputs local time. I'm very new to javascript so I can't find the right property to use instead of .toIsostring. What should I do ? function nextWeekdayDate(date, day_in_week) { var ret = new Date(date || new Date()); ret.setDate(ret.getDate() + (day_in_week - 1 - ret.getDay() + 7) % 7 + 1); return ret; } let nextFriday =

How to resolve loss of minute precision formatting a moment in 12HR?

拟墨画扇 提交于 2019-12-25 07:23:48
问题 I've converted an ISO date string to a momentjs moment and then formatted that moment using .format("MM/DD/YYYY HH:MM") . When I output the final formatted moment, the minute value is incorrect as against the value read back from the iso string originally. In this case the ISO string value holds 3:10 PM or "2016-08-03T03:10:00.000Z" as represented in the string. But when I call format the moment value is 4:07PM meaning three minutes have been subtracted during the format. During debug I noted

Why converting new.Date() .toISOString() changes the time?

天大地大妈咪最大 提交于 2019-12-21 07:29:23
问题 I'm inserting a date in a database in two different format. this is inserting as Datetime var mydate; mydate = new Date(); document.getElementById('clockinhour').value = mydate.toISOString().slice(0, 19).replace('T', ' '); Output A 2017-06-21 20:14:31 this is inserting as varchar : document.getElementById('clocked_in_time').value = Date(); Output B Wed Jun 21 2017 16:14:31 GMT-0400 (Eastern Standard Time) Output B is the correct time but I need to display output A. What causes the time to

How to convert each col by index in a table to local moment?

五迷三道 提交于 2019-12-12 02:24:37
问题 I have a table containing 8 columns. Each date value in the final column needs to be converted to the browser local. At the moment it shows as UTC: So I added some JQuery to loop through each row at the index using .eq(index) which works out to be index '6' in JQuery. But when I test this function it only converts the last row UpdatedTime in the table and the time is not local as seen below: How can I convert each row at a specified column to local moment? This is the JQuery function I use to

Locale time on IONIC2 Datetime picker

爷,独闯天下 提交于 2019-12-11 04:13:37
问题 I'm working with IONIC2, Angular2 and Typescript. I have an Datetime working as follows: page.html <ion-datetime displayFormat="DD MMMM YYYY" pickerFormat="DD MMMM YYYY" [(ngModel)]="date"></ion-datetime> page.ts date: string = new Date().toISOString(); The ion-datetime field shows time with an hour less, how can I display date on Datetime picker considering the timezone? 回答1: Reading this answer I solve my problem. Finally I use: moment(new Date().toISOString()).locale('es').format(); Thanks

Why converting new.Date() .toISOString() changes the time?

允我心安 提交于 2019-12-04 01:46:30
I'm inserting a date in a database in two different format. this is inserting as Datetime var mydate; mydate = new Date(); document.getElementById('clockinhour').value = mydate.toISOString().slice(0, 19).replace('T', ' '); Output A 2017-06-21 20:14:31 this is inserting as varchar : document.getElementById('clocked_in_time').value = Date(); Output B Wed Jun 21 2017 16:14:31 GMT-0400 (Eastern Standard Time) Output B is the correct time but I need to display output A. What causes the time to change when converted toISOString? How can I fix this? In your this is inserting as Datetime block your