momentjs

Fetch week number and week start & end date using bootstrap datepicker

五迷三道 提交于 2019-12-25 03:32:42
问题 BootStrap DateTimePicker is there any option available to fetch the week number and week start and end date from the calendar. Demo link $('#datetimepicker1').datetimepicker({ format: 'DD/MM/YYYY', calendarWeeks:true }); Something similar to the HTML5 week attribute <input type="week"/> 回答1: I would rely on moment to provide the data you are looking for, specifically the Day of Week and Format functions http://momentjs.com/docs/#/get-set/day/ http://momentjs.com/docs/#/displaying/format/ See

Using moment.js trying to create an event in native IOS calendar

萝らか妹 提交于 2019-12-25 02:29:44
问题 I have used the "datetime-local" input to get a start date and an end date from the user to put into the native calendar. This is my code to get and format the "datetime-local": var s = $("#startDate").val(); var startDate = moment(s).toDate(); var e = $("#endDate").val(); var endDate = moment(s).toDate(); This code takes the correct date, but it makes the time set to an all day event. For example, if I put in 1:00 o'clock on 7/21/2014 as the start date and then 1:00 o'clock on 7/22/2014 it

Date of Joining calculation not working with moment 2.19.1

蹲街弑〆低调 提交于 2019-12-25 01:36:24
问题 Below code not working with "moment": "^2.19.1", var a = moment([2017, 12, 09]); var b = moment([2011, 02, 17]); var years = a.diff(b, 'year'); b.add(years, 'years'); var months = a.diff(b, 'months'); b.add(months, 'months'); var days = a.diff(b, 'days'); console.log(years + ' years ' + months + ' months ' + days + ' days'); Please help. 回答1: You can use moment duration format. Include moment duration format plugin, and then.. var duration = moment.duration(a.diff(b)); console.log(duration

moment JS get name of the day in different language

隐身守侯 提交于 2019-12-24 18:12:54
问题 I am trying to get the name of the day in French using Moment.js moment("01-06-2018").locale("Fr").format("dddd") This returns " Saturday " whereas I want to get the name of the day in French 回答1: Please make sure you have imported fr locale and do not use moment(String) with non ISO 8601 inputs, use moment(String, String) instead. As locale docs says: By default, Moment.js comes with English (United States) locale strings. If you need other locales, you can load them into Moment.js for later

moment locale not set correctly

醉酒当歌 提交于 2019-12-24 17:02:08
问题 We're trying to find a problem with tests that use moment.js and fail when run on a server in Arizona but succeed when run locally here in the UK. We manually set the locale before creating a moment and can see that the local 'en-gb' is installed. This fiddle highlights what I think the problem is ( Need to set computer to Arizona Time zone first! ) https://jsfiddle.net/2ve10ax4/ moment.locale('en-gb'); console.log(moment.locale()); // en-gb console.log(moment('2016-05-01T00:00:00+00:00')

moment.js timezone inconsistency

淺唱寂寞╮ 提交于 2019-12-24 16:31:16
问题 I am formatting a given date using momentjs. The following behaves differently in different timezones: moment(new Date("2016" + "-" + "06" + "-01").toISOString()).format('MMMM YYYY') It gives me May 2016 in timezone of America/Denver and June 2016 in Asia/Karachi. I tested by changing the browser timezone to different timezones. It should be June 2016 in both. When i change the format in new Date() to use slashes instead of hyphens like below, it gives me correct result in both timezones i.e.

How can I build a 'moment' function that works in a non-global locale?

痞子三分冷 提交于 2019-12-24 16:00:26
问题 With MomentJS, if necessary I can set a locale on a specific moment instance (rather than globally) using .locale (or .lang in older versions). How can I create a function equivalent to moment (all 42 signatures of it) that always works in a specific locale that's different from the global? I have a submodule within a web project that has to work with a custom locale. We don't want this locale used outside this particular submodule, but we want it used consistently within that submodule. So I

Moment.js round dates up

前提是你 提交于 2019-12-24 14:36:36
问题 In my javascript the library Moment.js rounds my dates up. Date: 2015-02-09T23:00:00.000Z moment(Date).format('DD/MM'); ==> Becomes 10/02 I want 09/02 as result. Is there a possible way that the library not rounds the date? 回答1: You can try like below. moment(Date,['YYYY-MM-DD']).format('DD/MM'); 回答2: The problem is likely one of timezones: by default, momentjs parses your string and converts it to your local timezone. If I see this correctly, the 'Z' in your date signifies zulu - or UTC time

How to get today start time and current time of EST using Moment.js

房东的猫 提交于 2019-12-24 13:52:34
问题 I want to create Start and End Time stamp using Moment.js (EST): StartTime would be today's start time EndTime would be current time. I have used moment.js and created like this var time = new Date(); var startTime=Date.parse(moment(time).startOf('day').tz('America/New_York').format("MM/DD/YYYY HH:mm:ss")); var endTime=Date.parse(moment(time).tz('America/New_York').format("MM/DD/YYYY HH:mm:ss")); It is giving time in milliseconds. Is it correct or wrong? I am not getting data from db because

Moment different behaviour on different browsers

本小妞迷上赌 提交于 2019-12-24 13:23:01
问题 Let the following snippet: var dateJS = new Date("1950-09-09T23:00:00.000Z"); var dateMoment = moment("1950-09-09T23:00:00.000Z"); console.log("Javascript Epoch Time:", dateJS.valueOf()); console.log("Moment Epoch Time:", dateMoment.valueOf()); console.log("Is DST?", dateMoment.isDST()); <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment.min.js"></script> If you run it with some Firefox versions (such as Firefox 61.0.1) or with Microsoft Edge you get Is DST? true .