momentjs

moment.js get yesterday time range from midnight to midnight

扶醉桌前 提交于 2020-07-17 06:00:10
问题 How can I get the time range for yesterday from midnight until midnight: Example: Yesterday 22.07.2015 Result: 22.07.2015 00:00:00 (AM) 22.07.2015 23:59:59 (PM) Date format doesn't matter this is just an example. 回答1: moment().subtract(1,'days').startOf('day').toString() "Thu Jul 30 2015 00:00:00 GMT-0600" moment().subtract(1,'days').endOf('day').toString() "Thu Jul 30 2015 23:59:59 GMT-0600" 来源: https://stackoverflow.com/questions/31593445/moment-js-get-yesterday-time-range-from-midnight-to

moment.js get yesterday time range from midnight to midnight

对着背影说爱祢 提交于 2020-07-17 06:00:10
问题 How can I get the time range for yesterday from midnight until midnight: Example: Yesterday 22.07.2015 Result: 22.07.2015 00:00:00 (AM) 22.07.2015 23:59:59 (PM) Date format doesn't matter this is just an example. 回答1: moment().subtract(1,'days').startOf('day').toString() "Thu Jul 30 2015 00:00:00 GMT-0600" moment().subtract(1,'days').endOf('day').toString() "Thu Jul 30 2015 23:59:59 GMT-0600" 来源: https://stackoverflow.com/questions/31593445/moment-js-get-yesterday-time-range-from-midnight-to

Add day to date with momentjs

对着背影说爱祢 提交于 2020-07-16 06:22:08
问题 I am trying to add a day to my date: let createdDate = moment(new Date()).utc().format(); let expirationDate = moment(createdDate).add(1, 'd'); console.log(expirationDate); However, this keeps returning an obscure object {_i: "2017-12-20T21:06:21+00:00", _f: "YYYY-MM-DDTHH:mm:ss Z", _l: undefined, _isUTC: false, _a: Array(7), …} fiddle: http://jsfiddle.net/rLjQx/4982/ Does anyone know what I might be doing wrong? 回答1: You are logging a moment object. As the Internal Properties guide states:

React native : moment not working for specific time value without debug mode

徘徊边缘 提交于 2020-07-14 11:57:27
问题 I have below code where I format the time value to be date format. const arrivalDateTime = moment( `${todaysDate.format("YYYY-MM-DD")} ${arrivalTime}:00:00`, ).toDate(); When debug mode is off, if I select 8 or 9 value from the control, its not able to format the value. When I am in debug mode, and select 8 or 9, its able to format the value as: Fri May 22 2020 09:00:00 GMT-0600 (Mountain Daylight Time) I have seen many threads discussing the same issue but solution provided in them haven not

React native : moment not working for specific time value without debug mode

ⅰ亾dé卋堺 提交于 2020-07-14 11:56:26
问题 I have below code where I format the time value to be date format. const arrivalDateTime = moment( `${todaysDate.format("YYYY-MM-DD")} ${arrivalTime}:00:00`, ).toDate(); When debug mode is off, if I select 8 or 9 value from the control, its not able to format the value. When I am in debug mode, and select 8 or 9, its able to format the value as: Fri May 22 2020 09:00:00 GMT-0600 (Mountain Daylight Time) I have seen many threads discussing the same issue but solution provided in them haven not

How to get timezone offset from the date getting from client side?

风格不统一 提交于 2020-07-10 10:25:18
问题 I am working with nodejs. I am getting the startDate as startDate: '2020-06-14T18:30:00.000Z' from the client side. I need to get the timezone offset from the above date. It should be +05:30. How can I get that? Edit: Server always works on UTC. So can I get the timezone offset by subtracting the date coming from the client by the UTC one? i.e. '2020-06-14T18:30:00.000Z' - moment.utc().startOf("day") = +05:30 回答1: If the node.js syntax is the same as plain JS; declare a date object with: var

How to get timezone offset from the date getting from client side?

旧巷老猫 提交于 2020-07-10 10:24:10
问题 I am working with nodejs. I am getting the startDate as startDate: '2020-06-14T18:30:00.000Z' from the client side. I need to get the timezone offset from the above date. It should be +05:30. How can I get that? Edit: Server always works on UTC. So can I get the timezone offset by subtracting the date coming from the client by the UTC one? i.e. '2020-06-14T18:30:00.000Z' - moment.utc().startOf("day") = +05:30 回答1: If the node.js syntax is the same as plain JS; declare a date object with: var

Date went wrong when using Momentjs date format in IE 11

三世轮回 提交于 2020-07-10 07:43:08
问题 I am using Moment.js format function on a current date as var startDate = moment(new Date()).format('MM/DD/YY'); The result is 06/28/20 What happens is that it retains only the year part: 20 as "06/28/20" , after I used new Date(startDate) , the result is "Mon Jun 28 1920 00:00:00 GMT+0530 (India Standard Time)" . After this when I applied another format on "06/28/20" : startDate = moment(startDate ).format('MM-DD-YYYY'); The result is 06-28-1920 In Google Chrome and Firefox it gives the

Is Zone abbreviation using moment-zone library a dynamic

依然范特西╮ 提交于 2020-07-10 03:37:25
问题 I am using moment timezone library to show the zone abbreviation after the timestamp. I am using the following snippet to show the zone abbreviation of New York, USA var timeZone = moment.tz.guess(); const zoneName = moment.tz(timeZone).zoneName(); return moment().tz("America/New_York").zoneName(); This returns me the Zone abbreviation EDT . My question is: when winter will come will it automatically return EST ? 回答1: Yes, it will. var jun = moment("2014-06-01T12:00:00Z"); var dec = moment(

Some code only works while chrome debugger is active

旧巷老猫 提交于 2020-07-09 07:36:15
问题 I'm working on a react-native application and I'm trying to format a date using moment. Dates look like "02-16-2016 09:04:23" function formatTime(date){ var formattedDate = moment(date).format('MM:ss A'); return formattedDate; } Works fine if the chrome debugger is active. But if I disable it, all I get is "invalid date" Same thing with a decoding function I'm using var that = this; MessagesService.getMessageBody(selectedMessage) .then(function(messageBody){ var decodedData = window.atob