momentjs

Sorting of array with Moment(date) elements

余生长醉 提交于 2020-02-03 06:30:48
问题 I have an array that is populated with moment(Date provided by the database) elements. I am trying to sort the array so that the first element is the oldest and the last element is the newest, but with no success. for (let item of items) { dates.push(moment(item.created)); } dates.sort(function(a,b){ var da = new Date(a).getTime(); var db = new Date(b).getTime(); return da < db ? -1 : da > db ? 1 : 0 }); } console.log(dates); This always prints the current time times number of elements. 回答1:

How to set time with date in momentjs

≡放荡痞女 提交于 2020-01-31 21:03:46
问题 Does momentjs provide any option to set time with particular time ? var date = "2017-03-13"; var time = "18:00"; var timeAndDate = moment(date).startOf(time); console.log(timeAndDate); <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script> 回答1: Moment.js does not provide a way to set the time of an existing moment through a string. Why not just concatenate the two: var date = "2017-03-13"; var time = "18:00"; var timeAndDate = moment(date + ' ' + time);

Properly formatting a local UTC date string when dealing with an Arabic locale

倖福魔咒の 提交于 2020-01-30 12:28:46
问题 I'm using moment.js and moment-timezone to get a local utc date string. I've created the function below to achieve this. When trying to use this when dealing with an Arabic locale I'm getting invalid date returned. function _getLocalUtcDateString(utcDateString, timezoneId) { var utcMoment = moment.utc(utcDateString, 'MM/DD/YYYY hh:mm:ss A').format('MM/DD/YYYY hh:mm:ss A'); var localTimeTz = moment.utc(utcMoment).tz(timezoneId).format('MM/DD/YYYY hh:mm:ss A'); return localTimeTz; } If I call

How to get the integer value of month from moment.js

余生颓废 提交于 2020-01-30 11:52:06
问题 I am using Moment.js for adding dates to an option list I am making, so that I can use those dates to show available appointments, for example, someone can select Friday, February 3rd from the option list and then a list of available times will show up for February 3rd. What I am having trouble with is I am using an online scheduling api that takes month values that start at 1, for example, January is 01, February is 02, etc. but moment.js months start at 0 and only go up to 11, for example,

Angular material date picker format locale

随声附和 提交于 2020-01-30 11:49:05
问题 I have created an angular material date picker component to use with formly , and tried to set it to use GB for the locale so that dates are shown as 26/07/2019 . However, when typing in the date, it parses as US still, resulting in invalid date errors being shown. I have tried to include moment and the MomentDateAdapter module but have been unable to solve the issue. Here is a stackblitz I've set my providers like so: providers: [ { provide: LOCALE_ID, useValue: 'en-GB' }, { provide:

Angular material date picker format locale

只愿长相守 提交于 2020-01-30 11:48:36
问题 I have created an angular material date picker component to use with formly , and tried to set it to use GB for the locale so that dates are shown as 26/07/2019 . However, when typing in the date, it parses as US still, resulting in invalid date errors being shown. I have tried to include moment and the MomentDateAdapter module but have been unable to solve the issue. Here is a stackblitz I've set my providers like so: providers: [ { provide: LOCALE_ID, useValue: 'en-GB' }, { provide:

How to get date & time using moment.js

99封情书 提交于 2020-01-30 08:28:05
问题 I need to get the start date and end date in the below format using moment js startDate = 20160427000000 and endDate = 20160427235959 Here the start date appended with 000000 and end date appended with 235959 What is the right way to get this result in javascript 回答1: You want the format operator. Since it looks like your 0's and 2359's are hardcoded (I assume you're doing start and end of days), try: startDate = moment().format('YMMDD000000'); endDate = moment().format('YMMDD235959'); EDIT:

How to send Timespan to WebAPI from Javascript

纵饮孤独 提交于 2020-01-30 05:28:08
问题 I have two moment dates and am calculating the duration by doing the diff between both. How can I post the duration to the WebAPI controller so that it is automatically deserialize to a C# TimeSpan? When I post "P2DT00H" it will deserialize properly to a TimeSpan but how can I get that format from a moment duration? 回答1: Calculate the duration as described in this answer Get the time difference between two datetimes Define an endpoint like this: public IHttpActionResult Post([FromBody]

How format a time in hours greater than 24 hours AngularJS

99封情书 提交于 2020-01-25 21:58:52
问题 I have a decimal value in minutes with the value 3361 and need to convert in hours and present in this format: 56:01:00 I tried this code: $scope.myTime = new Date(1970, 0, 1).setMinutes(3361); <input type="text" class="form-control" ng-model="myTime | date:'HH:mm:ss'"> But the result is not that I expected: 08:01:00 回答1: I fear that you can't acheive what you need using angular date filter. You can create you custom filter (here angular official guide) and build the result in the format you

fullCalendar event resizing is not working when time is added in start and end date

微笑、不失礼 提交于 2020-01-25 09:40:11
问题 Whenever I put the time in start and end, the event won't resize. But when the time is in 00:00:00 I can now resize it. Then it works when the time is 00:00:00. My full code: $(document).ready(function() { $('#calendar').fullCalendar({ header: { left: 'today add_event', center: 'prev title next', right: 'month,basicWeek,basicDay' }, eventOrder: 'start', editable: true, eventLimit: true, selectable: true, selectHelper: true, select: function(start, end) { $('#ModalAdd #start').val(moment(start