momentjs

How to get all sundays/mondays/tuesdays between two dates? [duplicate]

那年仲夏 提交于 2019-12-30 10:26:35
问题 This question already has answers here : How do I calculate number of given weekday between range using Moment JS? (4 answers) Closed 3 years ago . Given a start date and an end date, how can I get all the, e.g. Sundays between September 1st and November 2nd? Note - not a duplicate: I don't want a count , but rather the individual dates as either javascript dates or momentjs objects (The answer linked in the other SO question is asking for a count ) 回答1: Use a loop to continually get the date

Using moment.js, how to display the current date format for the user?

China☆狼群 提交于 2019-12-30 09:28:08
问题 Given a text field, I want to have a suitable placeholder. A typical placeholder will be something like: "mm/dd/yyyy". However, I would like to use locale-aware dates using moment.js. This means that I will be specifying "l" as the moment.js date format, howe do I determine the date format that moment.js will be using in this case? The user will not understand what "l" means, so using this value in the placeholder text makes very little sense. Specifically, I am hoping to be able to access

Moment.js timezone valueOf returning wrong timestamp

Deadly 提交于 2019-12-30 07:32:10
问题 I want to use moment.js to shift an input moment to a different timezone and get its timestamp. moment.tz(moment(), "Pacific/Auckland").valueOf(); The problem is, while I am doing this, the moment.tz( ) object is looking good, but the valueOf() method is somehow calculating this back to timezone which is set on my computer. What is wrong with my approach? Thanks very much. EDIT 1 moment.tz(moment(), "Pacific/Auckland").format(); is giving me the right time string moment.tz(moment(), "Pacific

Updating time offset with moment().utcOffset()

时光怂恿深爱的人放手 提交于 2019-12-30 03:50:11
问题 I'm facing some issue trying to use moment.js for dealing with time offsets. I collect in an hidden input the local user time offset: <script type="text/javascript"> $(document).ready(function () { $('input#timeoffset').val(moment().utcOffset()); }); </script> The offset gets correctly stored (in my case its value is -240). Later on the server side (which runs in utc time) I try to update some db stored utcDate doing something like: var userDate = moment(utcDate).utcOffset(offset) My issue is

Angular Moment : Moment Timezone has no data for America/New_York

别说谁变了你拦得住时间么 提交于 2019-12-29 08:27:26
问题 Date received from server is in UTC timezone and I need to convert it to a particular timezone, for example : America/New_York .Following is the code for same <span class="bold" ng-bind="sess.date_time | amTimezone:'America/New_York' | amDateFormat:'h:mm a'"></span> But on doing so I get the following error: Moment Timezone has no data for America/New_York. See http://momentjs.com/timezone/docs/#/data-loading/. But America/New_York is a known timezone to moment but still it is asking me to

Initialize a Moment with the timezone offset that I created it with

余生颓废 提交于 2019-12-28 18:14:06
问题 I'm using moment and moment-timezone in javascript, and this part of it is one of the most unintuitive API's I've ever seen. I would expect that: moment("2015-12-14T04:00:00Z").utcOffset() would be a pure function and return the offset included in the argument, which is 0. But instead it implicitly converts it to my local timezone offset (PST), so this returns -480 Why?? I asked what offset the object i just created has, not what offset I'm currently in. It would be like if I wrote an api

Round a timestamp to the nearest date

半腔热情 提交于 2019-12-28 04:08:28
问题 I need to group a bunch of items in my web app by date created. Each item has an exact timestamp, e.g. 1417628530199 . I'm using Moment.js and its "time from now" feature to convert these raw timestamps into nice readable dates, e.g. 2 Days Ago . I then want to use the readable date as a header for a group of items created on the same date. The problem is that the raw timestamps are too specific - two items that are created on the same date but a minute apart will each have a unique timestamp

How do I change the language of moment.js?

随声附和 提交于 2019-12-28 03:20:09
问题 I am trying to change the language of the date which is being set by moment.js. The default one is English, but I want to set the German language. These is what I tried: var now = moment().format("LLL").lang("de"); It’s giving NaN . var now = moment("de").format("LLL"); This isn’t even reacting. var now = moment().format("LLL", "de"); No change: this is still producing a result in English. How is this possible? 回答1: You need moment.lang ( WARNING : lang() is deprecated since moment 2.8.0 ,

Moment js date time comparison

隐身守侯 提交于 2019-12-27 10:21:22
问题 I'm using moment.js to format my date time, here I have two date values, and I want to achieve a particular function when one date is greater than the other. I read most of their docs, but didn't find the function to achieve this. I know it will be there. This is my code: var date_time = 2013-03-24 + 'T' + 10:15:20:12 + 'Z' var d = moment(date_time).tz('UTC'); // first date var now = new Date(), dnow = moment(now).tz('UTC'), snow = dnow.minute() % 15, diffnow = 15 - snow, tonow = moment(dnow)

Moment js date time comparison

◇◆丶佛笑我妖孽 提交于 2019-12-27 10:20:13
问题 I'm using moment.js to format my date time, here I have two date values, and I want to achieve a particular function when one date is greater than the other. I read most of their docs, but didn't find the function to achieve this. I know it will be there. This is my code: var date_time = 2013-03-24 + 'T' + 10:15:20:12 + 'Z' var d = moment(date_time).tz('UTC'); // first date var now = new Date(), dnow = moment(now).tz('UTC'), snow = dnow.minute() % 15, diffnow = 15 - snow, tonow = moment(dnow)