momentjs

How to get previous date in javascript

此生再无相见时 提交于 2020-06-16 22:21:26
问题 I have one date but i want to get previous date from that.How we can do using javascript or momentjs? Demo:https://stackblitz.com/edit/js-ykswiz?file=index.js date format dd-mm-yyyy. Example: var date1=new Date("08-06-2020"); console.log("Prev Date="+date1.getDate() - 1);// Prev Date=07-06-2020 var date2=new Date("01-06-2020"); console.log("Prev Date="+date2.getDate() - 1);// Prev Date=31-05-2020 var date3=new Date("01-01-2021"); console.log("Prev Date="+date3.getDate() - 1);// Prev Date=31

Moment js - get date without considering time zone

大城市里の小女人 提交于 2020-06-12 05:27:07
问题 I did read different StackOverflow posts and they suggested to use .utc from moment but it doesn't work Note: I am on PST zone const start = '2018-06-10T21:00:00-04:00'; const end = '2018-06-10T23:00:00-04:00'; const noconversion = moment.utc(start).format('MM/DD/YYYY'); const converted = moment(end).format('MM/DD/YYYY'); Current output: noconversion - 2018-06-11 converted - 2018-06-11 Output expected: 06/10/2018 just fetch date from date provided CODEPEN Link 回答1: Have you tried parseZone?

Get ISO string from a date without time zone

北城余情 提交于 2020-06-10 02:24:09
问题 My configuration is Lisbon time zone. When I do new Date() I get my current local date/time which is Fri Apr 28 2017 01:10:55 GMT+0100 (GMT Daylight Time) When I get the ISO string with toISOString() it will apply the time zone and I will get: 2017-04-28T00:10:55.964Z The problem is that some minutes ago the date time was like this (yesterday): 2017-04-27T23:45:05.654Z I tried moment.js (new to this) and I did something like this document.write(moment('2017-04-28').format()) But I get this

How to format x-axis based on how long between start and end time datepicker of data in chart.js?

自闭症网瘾萝莉.ら 提交于 2020-06-01 05:08:18
问题 Hello I am new to javascript. I have chart.js with the data from API look like this : .....//datepicker code...... $.ajax({ method: "GET", url: endpoint, data: { startDate: startDate, endDate: endDate }, success: function(data){ //get data by fields var accelero_x = [], timestamp = []; for (var i=0; i<data.length; i++){ accelero_x.push(data[i].accelero_x); timestamp.push(data[i].timestamp); } //plot the chart var ctx = document.getElementById("accelero_xChart").getContext('2d'); var accelero

How to group by object by date?

非 Y 不嫁゛ 提交于 2020-05-08 09:49:09
问题 I fetching data form database and I want to send response date wise. I want little bit of help in group By my data with date wise. I have Object like as below var IHAVE = [{ "foodId": "59031fdcd78c55b7ffda17fc", "qty": 1, "dateTime": "2017-07-26T12:03:06.000Z", "_id": "591c3bfcca93e86c3450a537" }, { "foodId": "59031fdcd78c55b7ffda17fc", "qty": 1, "dateTime": "2017-05-18T04:21:13.000Z", "_id": "591d213b6878badb0621b840" }, { "foodId": "59031fdcd78c55b7ffda17fc", "qty": 1, "dateTime": "2017-07

Formatting MomentJS duration above 24 hours

a 夏天 提交于 2020-04-10 07:46:31
问题 I would like to format a summed up total working hours e.g. 49.75 to this: 49:45 . When I use duration like this: const dur = moment.duration(49.75, 'hours').asMilliseconds(); moment.utc(dur).format("HH:mm:ss") // 01:45:00 I'll receive 01:45:00 instead of 49:45:00 Is there a way to format (instead of HH ) duration without dropping the days? 回答1: I recommend you this answer. You can add a format for the duration, and it works for greater than 24 Hour. function(input) { input = input || ''; var

Moment JS Subtract method returns 12 hour difference when there is only zero hour left [duplicate]

牧云@^-^@ 提交于 2020-03-24 09:45:27
问题 This question already has answers here : Get the time difference between two datetimes (14 answers) Closed 4 years ago . I want to display remaining hours, minutes and seconds to a specific preset time (01:00 PM) from the current time with help of moment js. I am using the following code, var n = new Date(); var end = new Date(n.getFullYear(), n.getMonth(), n.getDate(), 13, 0, 0, 0); var a = moment(end); var b = moment(n); var eta = a.subtract(b).toDate().toLocaleTimeString(); It works fine

MomentJS get weekNumber with variable first day of week

故事扮演 提交于 2020-03-19 08:03:40
问题 I'm trying to get the weeknumer of a date, but I want it to work with a variable first day of the week. A user is able to set the first day of the week. I couldn't find a javascript solution, so I tried moment. Unfortunately, I couldn't find a way to set the first day of the week. E.g. Sunday for US, Monday for the EU, but it would be nice if it could be any other day as well. 回答1: Moment supports i18n, you can change locale globally or change locales locally and update first day of the week

Setting date range picker start date to blank

我怕爱的太早我们不能终老 提交于 2020-03-17 09:30:38
问题 I have a daterange picker based on http://www.daterangepicker.com 's daterange picker and I want to set the start date to empty. This will work for what I want to do. I'm using an text input field to get the dates </span><input type="text" class="form-control" id="reservation" /> On the site there is an example of setting "Input Initially Empty" but I couldn't get it to work. Basically I don't know where to set it as it seems. My daterange picker is inside a partial view and it called by

How to properly convert end_time timestamp into date

一笑奈何 提交于 2020-03-03 02:24:13
问题 I'm requesting data from Facebook Insights API with granularity set to a day, let's take likes as an example. My request goes to: PAGEID/insights/page_fan_adds_unique/day Response looks like this: { "data": [ { "id": "PAGEID/insights/page_fan_adds_unique/day", "name": "page_fan_adds_unique", "period": "day", "values": [ { "value": 3, "end_time": "2014-08-29T07:00:00+0000" }, { "value": 4, "end_time": "2014-08-30T07:00:00+0000" }, { "value": 1, "end_time": "2014-08-31T07:00:00+0000" } ],