FAQ Database Discussion Community


Moment.js Get difference between two dates in the dd:hh:mm:ss format?

javascript,date,momentjs
I am calculating the time until 11:59PM of the current day. Here is an example. <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.js"></script> <script> setInterval(function() { var now = moment(); var mid = moment(); mid = mid.endOf('day'); var diffHours = mid.diff(now, 'hours'); var diffMinutes = mid.diff(now, 'minutes'); var diffSeconds = mid.diff(now, 'seconds'); console.log(diffHours + "h "...

How to compare two dates in moment.js [duplicate]

javascript,jquery,angularjs,date,momentjs
This question already has an answer here: Moment js date time comparison 3 answers I am using moment.js in my application, I pass my date in a particular format to moment.js and it compares it with the system time and give me the pretty time format, like this: moment(time,...

Time zone conversions

javascript,date,timezone,momentjs
I am having the start and end date as below, Start Date: "2015-02-19T00:00:00-08:00" End Date: "2015-02-19T17:00:00-08:00" as you see the date format is in PST so the date is fine in PST time zone,the snippet i am using as below, moment(StartDate).format("MMM Do"); but when i view the same page in...

How to display dates in my app without excessive load?

meteor,momentjs
In my application I have posts, and in my post page I'm showing posted date as a minute ago using moment package. I'm displaying dates using the following code Template.registerHelper("postedTime",function(date){ return moment(date).fromNow(); }); and in my HTML {{#with post}} ............. ............ {{postedTime date}} ............ ............ {{/with}} I know these dates...

Deprecation warning: moment construction falls back to js Date

javascript,momentjs
I am attempting to convert this datetime 150423160509 //this is utc datetime To the following format: 2015-04-24 00:05:09 //local timezone by using the moment.js var moment = require('moment-timezone'); var a = moment.tz('150423160509', "Asia/Taipei"); console.log( a.format("YYYY-MM-DD H:m:s") ); but it gives me this error Deprecation warning: moment construction falls back to...

Cannot read property 'tz' of undefined - Ember Moment Timezone

javascript,ember.js,timezone,momentjs
I have an ember app that I am trying to add moment with time zone into: { "name": "front-end", "dependencies": { "handlebars": "~1.3.0", "jquery": "^1.11.1", "ember": "1.8.1", "ember-data": "~1.0.0-beta.14.1", "ember-resolver": "~0.1.7", "loader.js": "stefanpenner/loader.js#1.0.1", "ember-cli-shims": "stefanpenner/ember-cli-shims#0.0.3", "ember-cli-test-loader": "rwjblue/ember-cli-test-loader#0.0.4", "ember-load-initializers": "stefanpenner/ember-load-initializers#0.0.2", "ember-qunit": "0.1.8", "ember-qunit-notifications": "0.0.4",...

Displaying inaccurate date using moment.js

jquery,node.js,momentjs
Using nodejs, jade and moment.js <div class="post-date"> #{entry.published_at} </div> Every time user creates entry and the date published is updated. It is dynamic. Example: Raw date shows "Thu Jan 01 2015 08:00:00 GMT+0800 (SGT)" On web page, converting the raw date with momentjs so only Jan 01 2015 is displayed....

fromNow displays different strings on different browsers

javascript,timezone,momentjs
I pass a date string 2015/05/14-02:55 pm to moment.js constructor and i am using fromNow to convert it into a readable format. When i run this command on 16th May, chrome displays right output but mozilla says a few seconds ago. firefox console output: chrome console output: Is this a...

Add locale moment to an AngularJS app

angularjs,gruntjs,momentjs
I'm trying to configure the locale language for an AngularJS app based on Yeoman. When I serve the dist package after building my app (grunt build), the script reference dissapears. Here's a list of my dependencies on the index.html file. <!-- build:js(.) scripts/vendor.js --> <!-- bower:js --> <script src="bower_components/jquery/dist/jquery.js"></script> <script...

Convert time to DateTime using moment js

jquery,momentjs
I have time in HH:mm format like 13:15. I want to convert it into YYYY-MM-DD HH:mm using moment.js . I tried the following code. var t = "13:56"; var cdt = moment(t).format('YYYY-MM-DD HH:mm'); alert(cdt); I wanted output with the current date and given time like 2015-21-05 13:56...

How do I use two different relativeTime customizations?

momentjs
I'd like to use a short one in some places (eg {m: "1m"}) and a long one in others (eg {m: "one minute"}).

How to test a string is valid date or not using moment?

javascript,jquery,validation,date,momentjs
I would like to test if a date and or time entered is valid. Can this be done with moment as date and time testing with javascript seems a nightmare. (have spent hours on this). Test data looks like this. Invalid invalid = "" invalid = " " invalid =...

Get the last week date in Javascript

javascript,vb.net,date,momentjs
Here is my issue: I have 2 RadDatePickers see below: <telerik:RadDatePicker ID="rdpTimeOfDayFrom" runat="server" Culture="English (United States)"> <DateInput runat="server" DateFormat="MM/dd/yyyy"></DateInput> </telerik:RadDatePicker> <telerik:RadDatePicker ID="rdpTimeOfDayTo" runat="server" Culture="English (United States)"> <DateInput runat="server" DateFormat="MM/dd/yyyy"></DateInput> </telerik:RadDatePicker> By using JavaScript I want to get the last week date and set it in the...

What is the scope of moment.tz.setDefault() when used in Meteor?

javascript,datetime,meteor,timezone,momentjs
TL;DR What is the scope of moment.tz.setDefault()? I'm sure my problem here stems from my inexperience with both JavaScript and Meteor but I've been struggling with the problem for several straight days now. I'm working on an app that must take into account the client's timezone but I'm having significant...

Date time difference in moment.js

javascript,angularjs,local-storage,momentjs
Set the value into local storage : $scope.SetLocalStorage('My-' + $rootScope.UserId, moment()); Get the value form local storage : var dt = moment($scope.GetLocalStorage('My-' + $rootScope.UserId)); To get the date time from the local storage : var dTime = moment(dt); Here it shows invalid date : I need the time difference...

Showing update time like Twitter's update notification

javascript,momentjs
I am using momentJs for finding difference from now to a specific date as below: moment([MyDate]).fromNow(); The code gives me results as below: "a few minutes ago" or "10 hours ago" ... I tried to change that as below to find difference as seconds moment([MyDate]).fromNow().asSeconds(); but the code doesn't work....

FullCalendar today-button: date instead of text // issue with the lang

javascript,fullcalendar,momentjs,spip
I want to show the current date instead of a fixed text in the today-button. This >> irismediainfo3.lili.de is the development-website I am working on. I could not find an option for that in the docs, so I searched in the moment.js-docs and found: moment().format(); and used it in the...

Moment.js: how to update the time every minute?

javascript,jquery,momentjs
I'm using moment.js to display time on my webpage. I have the html div: <div id="time"></div> and the following javascript: <script> moment.tz.add('America/New_York|EST EDT|50 40|0101|1Lz50 1zb0 Op0'); var newYork = moment.tz("America/New_York").format('HH:mm a'); $('#time').append( "Current time in New York: "+newYork ); </script> When I run the page, it gives me the correct...

Angular Bootstrap DateTimePicker - Highlight Today Date on embedded Calender

angularjs,datetimepicker,momentjs,angular-bootstrap
Please accept my apologies if i had any mistakes in my post. This is my first post here. But, i am not new to StackOverflow. Correct me if any. I am using angular-bootstrap-datetimepicker library from the below url: Link to library I am currently embedding the calender on the page....

How do I change chromes Date-parsing / Sorting to match ff/ie Dateparsing?

javascript,jquery,google-chrome,date,momentjs
So I encounter a very weird problem here and am out of ideas at the moment. I've the following function to parse and sort a json object by its property RowDate, containing datestrings with the following format: "/Date(1389682861507+0100)/". orderByDate: function (json) { debug('[DataCollection::orderByDate], json before ordering: ', json); _.each(json.LineDefinitions, function...

One month from today with momentjs

javascript,momentjs
Could you tell me how to get the date where 1 month from today with moment.js. I have tried below one. myDate = moment().add(1, 'months'); resulted format is Fri Jun 26 2015 00:13:48 GMT+0530 But I need the format as this 06/26/2015.So how can I do that ? Thanks in...

Date not binding with model for specific culture

jquery,asp.net-mvc,datetime,momentjs,globalization
I am trying to bind date in a model for two cultures (en-US and fr-FR) when the culture is selected en-US. User selects the Item language for creating an entry. For example : Add news in en-US | add news in fr-FR Model: [Column(TypeName = "datetime2")] public DateTime CreatedOn {...

moment.js: convert timestamp and show month in German

javascript,momentjs
I have troubles displaying the month of the following operation in German: var date = moment.unix(valueTimestamp).format("DD. MMMM YYYY"); I have tried the following, but it does NOT work: // Attempt #1: var date = moment.lang('de').unix(valueTimestamp).format("DD. MMMM YYYY"); // Attempt #2: var date = moment.local('de').unix(valueTimestamp).format("DD. MMMM YYYY"); How do I achieve...

How to differentiate between a month, and the first day of a month in Moment.js

javascript,momentjs
In moment I am parsing dates from CSV, with the option to add formatting. Sometimes the dates are dates and will be handled as points in time. Sometimes the dates are fragments, describing a year, a month and so on. This will be handled as a range. See the following...

Date and time without timestamp in Javascript

javascript,date,jodatime,momentjs,datejs
In Javascript I need to work with the concepts of date, time and "date and time " without referring to a particular point in time. This is exactly the same semantics that joda time's LocalDate and LocalTime provide in Java. I've been briefly looking at Date.js and moment.js, but both...

Create moment Object from UTC string

javascript,date,momentjs,utc
I'm getting from my webservice an UTC date String such as the following : "2015-06-06T12:30:12Z" I need to display it following these 2 rules : If date < 1 week, display it like : 3 days ago or 23 mins ago.... If date > 1 week, display the date YYYY-DD-MM...

Moment: Check to see if date was within the last 3 days

javascript,momentjs
I am trying to see if any of the dates in an object are within the last 3 days of the current date using moment. The keys of the object are dates, but I am not sure how to use moment to compare them to the current date. Edit: The...

Evaluate two “DD-MM” strings as date and calculate before or after

javascript,date,momentjs
I am attempting to evaluate whether three dates are before or after each other and also if they are this year given the current DD-MM Example var firstPayment = moment('18-01', 'DD-MM'); var secondPayment = moment('18-07', 'DD-MM'); var todayDate = moment(10-02, 'DD-MM'); if(todayDate.isAfter(firstPayment) && todayDate.isBefore(secondPayment)) { lastInterestPaymentDate.text(firstPayment.add(-1,'years').format('DD MMM YYYY')); nextInterestPaymentDate.text(secondPayment.format('DD MMM...

Loading web-page with moment in electron

momentjs,electron
I am trying to load a web-page in an electron application, it is my first try to use electron so I am not familiar with it at all. The app is really simple: var app = require('app'); var BrowserWindow = require('browser-window'); app.on('ready', function() { browser = new BrowserWindow({ width:800, height:600...

format end date of time span using momentjs

javascript,localization,momentjs
I'm trying to format start and end date of a period. var fromDateAsString = moment("2015-01-01T00:00").format('??'); var toDateAsString = moment("2015-01-02T00:00").format('??'); console.log(fromDateAsString + ' - ' + toDateAsString); Expected result (german locale): 1.01.2015 00:00 Uhr - 1.01.2015 24:00 Uhr Solution should work for other locales too. My Questions: end date (1/2/15 00:00)...

isSame() function in moment.js or Date Validation

javascript,validation,date,momentjs
I need to validate the date from the user and check if it is in a particular format. If yes, then it will be accepted else it will not be. I am looking for sort of value.match("regular expression") The above works fine if, I have to choose from few formats....

How to get a specific date format using momentjs?

javascript,date,calendar,momentjs
I want to display the date clicked on in a specific format with localised strings, but although it shows the locale being set, the string I get is this: Fri Jun 05 2015 00:00:00 GMT+0300 (EEST) I would like to turn that into Friday, 5. June 2015 with localised words....

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

jquery,bootstrap,momentjs,bootstrap-datetimepicker
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"/> ...

Moment.js difference between flight departure and arrival

javascript,momentjs
var moment = require('moment-timezone'); var departure = moment.tz("2015-06-17T15:03:00.000", "America/Los_Angeles"); console.log("departure: " + departure.utc().format()); var arrival = moment.tz("2015-06-18T20:05:00.000", "Asia/Hong_Kong"); console.log("arrival: " + arrival.utc().format()); departureUTC = departure.utc(); arrivalUTC = arrival.utc(); var duration = moment(arrival.diff(departure)).format("h:mm"); console.log(duration); var durationUTC = moment(arrivalUTC.diff(departureUTC)).format("h:mm"); console.log(durationUTC);...

Define DateTime Formats and Convert One to another Using Momentjs

javascript,momentjs
I have one DateTime value in two different formats: 1. Sun Jun 28 2015 06:00:00 GMT-0400 2. 6/28/2015 6:00 AM Is there any terms/names commonly used that could uniquely define each one? And how to convert format 1 to 2 using Momentjs?...

Full calendar Timezone Moment js Issue

javascript,timezone,fullcalendar,momentjs
i've been wrestling with this for a while now, so reaching out for a bit of help please. I have a realtime multi timezone application that uses Signal R, all datetimes are stored and broadcast using UTC and I want to manipulate them client side to avoid multiple broadcasts for...

Convert date format 27.05.2015 01:46:32.UTC to Locale time

javascript,angularjs,html5,momentjs
Can anyone help me to convert date format 27.05.2015 01:46:32.UTC to Locale time. I tried the following code var date = new Date('27.05.2015 01:46:32.UTC '); date.toString(); This is also not working. Even momentjs is also gives error to convert this format of date....

Update relative time with MomentJS

javascript,time,momentjs
I'd like to create an object with the key set to the time a button was clicked. I'd then like to check every second the current time versus the time created and console.log() the relative time. The problem being it never changes from 'A few seconds ago'. What am I...

Moment .isAfter not returning correctly

javascript,momentjs
I have a string that is stored in UTC time. I am trying to see if this time is after the current UTC time. I am using momentjs and the isAfter() method returns the incorrect value when there is only 1 hour difference. The active_time variable happens at 15:00 utc....

Convert system date to ISO format using momentjs

javascript,momentjs
I'm trying to convert system date to ISO format in below fashion using momentjs 2015-02-17T19:05:00.000Z I'm however unable to find the parameter that I need to use to get it in the format which I want. I tried below piece of code.. moment().format("YYYY-MM-DD HH:mm Z"); I get output as 2015-02-02...

Convert JSON.NET date to jQuery UI Datepicker format

jquery,jquery-ui,datepicker,momentjs
I am serializing and passing a date out of my controller using JsonConvert.SerializeObject and sending it to a jQuery UI Datepicker field. Right now the output is like "2015-12-05T00:00:00" and I want it to be in a format of MM/DD/YYYY. My output is available via the AJAX returned data object...

Grouping using timestamp in ng-repeat

angularjs,momentjs
I have a bunch of tasks that I would like to group by their due date, currently each on has a created timestamp and I would like to use that to then organise the elements. Due Today Task 1 Task 2 Due this week Task 3 Task 4 Task 5...

Date String conversion in Python and momentjs

python,momentjs
Folks, I am very bad with date formatting and standards. What would be the pythonic way to convert the string 05/05/2015 to ISO 8601 2015-05-05T00:00:00.000Z ? I've found the moment.js alternative in python... zachwill/moment but I dont see a moment().toISOString(); Thanks!...

Datetime in MST Zone

javascript,c#,asp.net-mvc,angularjs,momentjs
On ASP.net MVC application where I save the date on datetime field in SQL sever db.It saves like this 2015-04-22 18:43:18.967.So now I need to show it as MST (Mountain Standard Time) on client side.So how can I do that ? I can use Moment.js or any other JavaScript library...

How does locale() work regarding timezones?

javascript,momentjs
I got a little bit confused about the locale(). Does it only change the language display or will it also change timezone? Can you give me some examples using the locale(), to show that it can change display or timezone?...

moment.js 2 digit year converting wrong 4 digit year

javascript,jquery,momentjs
Has anyone come across this issue with Moment.js: In Firefox using moment("6/12/15").format("M/D/YYYY h:mm:ss A") I get 6/12/1915 instead of 6/12/2015?

How to set a default offset in Moment.js?

javascript,momentjs
I'm currently using Moment.js to manipulate dates and times. I'm trying to avoid problems if the a user is changing manually the time on his device. So I'm getting the server time, checking the offset with the browser time. var offset = moment(browserTime).diff(moment(serverTime)); But I don't want to store that...

Parsing Apache Log Timestamps with JavaScript

javascript,mysql,apache,momentjs
I'm attempting to use moment.js to format Apache log timestamps (14/Jun/2015:11:05:54 -0700) as proper MySQL DATETIME format. Getting the MySQL DATETIME format is a breeze. But moment seems to only auto-detect ISO 8601 formats. My Node.js console output when passing in the Apache log's timestamp into moment: > moment( '08/Jun/2015:15:03:29'...

“getDate().toJSON()” loses a day

javascript,angularjs,date,momentjs,pikaday
I'm using the pikaday date picker plugin (through an angular directive and with momentjs) and sending the value to the server. Converting to json seems to lose a day though: var d = myPikaObject.getDate(); console.log(d); // Thu Apr 30 2015 00:00:00 GMT+0200 (SAST) console.log(d.toJSON()); // 2015-04-29T22:00:00.000Z I think this is...

How to find a specific time milliseconds in javascript?

javascript,javascript-library,momentjs
I am using moment.js.My code is like var nextDate = moment().add(30,'days'); This returns 30 day later date time.Now I want to convert this time in miliseconds.but I couldn't.How can I convert to date into miliseconds?Thanks...

Moment.js Include text in middle of date format

javascript,momentjs
I have a format of "Jan. 27, 2015 at 8:17 AM" that I need to display using moment.js. I'm using the format moment.format('MMM. D, YYYY at h:mm A z'); Everything works great except for the word "at". How can I get that word to display as a word instead of...

date range validation is valid if 'to date' not in same month as 'from date'

javascript,angularjs,date,momentjs
I have search date range 'from date' & 'to date' my validation function make data valid if range of date is not in same month ? for example if from date"2015-06-02" to date "2015-06-01" the range is invalid range? but if I make the to date "2015-05-31" it will be...

moment.js doesn't parse time from timestamp

javascript,angularjs,momentjs
I'm trying to parse a timestamp with moment.js from a json data set. When I use moment.format('MMMM Do YYYY, H:mm:ss'), the output is i.e. May 25th 2361, 0:00:00 for 12351223423. It's the same for all tested timestamps. Why doesn't it show the exact time/how to fix this? My Angular controller:...

How to convert asp.net json date format to DD-MM in javascript

javascript,datetime,momentjs,date-formatting
Hi i need help in converting data-time format. I'm using Cordova and JqueryMobile, my web services are in asp.net. In response of my Ajax call i get date in the format below. "/Date(1425935535000+0000)/" I need to convert it to DD-MMM format (i.e 13-Mar ) what utility i use to convert...

Time not getting converted to local time properly via moment.js

javascript,c#,momentjs,utc
11-06-2015 12:44:30 My datetime has the above format however it isn't getting converted to Local Time it gives me the month as November instead. var check = moment('@Model.Invoice.InvoiceDate').format('YYYY-MM-DD HH:mm:ss'); var localTime = moment.utc(check).toDate(); localTime = moment(localTime).format('YYYY-MM-DD HH:mm:ss'); console.log(localTime); White saving i am using DateTime.UTCNow function of C# and while getting...

how to convert milliseconds to Relative time?

jquery,date,momentjs
I use moment.js , I want to convert milliseconds to relative time Received from Database : 1423554515215 I wanna convert it to something like : ( 1 min ago ) OR ( 5 years ago ) UPDATE exactly Like stackoverflow post or comment timing ...

Abbreviated relative time (Instagram style) using momentjs?

javascript,datetime,momentjs
moment().startOf('day').fromNow() //6 hours ago. How can I change the above to show 6h instead?...

Momentjs : How to prevent “Invalid date”?

javascript,momentjs,invalidate
I have the following code : var fomattedDate = moment(myDate).format("L"); Sometimes moment(myDate).format("L") returns "Invalid date", I want to know if there is a way to prevent that and return an empty string instead....

Meteor upgrade to 1.0.3.1 now I get ReferenceError: moment is not defined

meteor,momentjs
After upgrading to Meteor 1.0.3.1 I now get this error ReferenceError: moment is not defined I can see here that it upgraded the momentjs to a newer version momentjs:moment added, version 2.8.4 mrt:moment removed from your project tsega:bootstrap3-datetimepicker upgraded from 3.1.3_1 to 3.1.3_3 Here is the code from the first...

Moment JS Returning Incorrect Value

javascript,node.js,momentjs
I am having some issues with the Moment JS NPM. I have a date in the past set to Jan 31st for testing. It is returning as 1 from today's date. Take a look at my code and screenshots below: var tz = -5, thisYear = moment().utc(tz).year(), // plus one...

.day() returns wrong day of month with Moment.js

javascript,datetime,momentjs
I am using Moment.js to parse a string and get the day, month and year separately: var date = moment("12-25-1995", "MM-DD-YYYY"); var day = date.day(); However, day is not 25—it's 1. What is the correct API method?...

How to convert iso-8601 duration to seconds using moment?

javascript,node.js,momentjs,iso
I have an iso-8601 duration which is as follows: PT15M51S I want to convert the duration into seconds so that I can store it in the db and order by duration etc. Here is what I tried so far: var moment = require('moment'); var duration = 'PT15M51S'; var x =...

Serializing dates in moment.js

javascript,momentjs
I have a calendar which is initialized this way: startDate: moment().subtract('month', 1).startOf('month'), endDate: moment() }, function(start, end) { // on date change - save it and retrieve later // start is the start date // end is the end date } I want to be able to save and restore...

Create a local date from a UTC date string in Moment.js

javascript,date,timezone,momentjs,utc
Given a UTC date string (formatted: YYYYMMDDHHmmss) I'd like to create a date with the local timezone using Moment.js. I have tried the following: var utcDateStr = '20140101120000'; var localDate = moment.utc(utcDateStr, 'YYYYMMDDHHmmss'); //actual: true //desired: false console.log(localDate._isUTC) //actual: "Wed Jan 01 2014 12:00:00 GMT+0000" //desired: "Wed Jan 01 2014...

How to find the closest time to the current time from an array using momentjs?

javascript,momentjs
I have an array of values [180, 360, 540, 720, 900, 1080, 1260]. Each array item describes the number of minutes after midnight UTC. Using momentjs, how can I find the array item closest to the current 'Europe/London' time? So far I have been able to get the current 'Europe/London'...

Momentjs start of day off by 4 minutes?

javascript,google-chrome,google-chrome-devtools,momentjs
this is exactly what i am putting into the chrome console: moment().startOf("day").format('MM/DD/YYYY HH:MM:ss') "04/27/2015 00:04:00" why could this be happening??...

moment.js - test if a date is today, yesterday, within a week or two weeks ago

javascript,date,momentjs
I am trying with moment.js to know if a date is today, yesterday, 1 week ago, or older (2 weeks ago or more). I already done that for the first two cases: var today = moment().startOf('day'); var yesterday = moment().subtract(1, 'days').startOf('day'); if (moment(localTime).isSame(today, 'd')) // today // do something if...

Moment with Timezone not properly formatting date

momentjs
I'm attempting to format 2014-10-03T23:09:42.764Z using Moment with Timezones so that I can properly display it for the app's users. However, no matter what timezone I input into Moment it still keeps displaying the current locale's timezone: (I'm in EST) moment('2014-10-03T23:09:42.764Z').tz('Europe/Paris').format() "2014-10-03T19:09:42-04:00" moment('2014-10-03T23:09:42.764Z').tz('Europe/London').format() "2014-10-03T19:09:42-04:00" Even though I input both London...

Format Moment.js Duration

javascript,momentjs
I am using Moment.js to track the duration of an action in my app. Currently, I have the following code: var startMoment = null; var actionClock = null; function startClock() { actionClock = setInterval(function(){ if (startMoment === null) { startMoment = moment(); $('#duration').text('00:00:00'); } else { var now = moment();...

How can I use duration() on local moment instance?

javascript,internationalization,momentjs
According to moment.js documentation you could create a local instance of moment to format a date using other locale than is globally set. That works fine with format(), but how can I use duration() on a local instance ? Here is what I tried: moment.locale('en'); var localMoment = moment("2015-03-12"); localMoment.locale('de');...

moment.js multiple live clocks using one function

javascript,jquery,momentjs
I'm building intranet project for my company, and there is a section for world clock which displays main world clocks like USA, Canada, UK, Australia ...etc. I have completed it using moment.js + hero-face script, and ended with this after my customisation: var nightStart = 18, nightEnd = 6; function...

Test in which ranges the collection of dates aren't overlapping

javascript,jquery,date,math,momentjs
I wrote a script to render a timeline with a dataset in javascript. But i have to mark the area's where no info is found (yellow in the image). I absolutely have no idea how to get the ranges without info in the dataset. (i use momentjs for date calculations)...

How to use the moment library in angular in a directive that uses compile instead of link

javascript,angularjs,recursion,angularjs-directive,momentjs
I have a tree of connected documents (parent to child) in my database from a single model called Actions, they're recursively compiled in an angular directive so that they're nested inside their parents. I have the following code: angular.module('crmDashboardApp') .directive('actionDirective', function ($http, $compile, RecursionHelper) { return { scope: { actionId:...

momentJS default locale is zh-tw and can't seem to overwrite it

javascript,angularjs,momentjs,angular-moment
I'm pulling the momentJS library from a CDN in my Angular app: <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script> The default locale is supposed to be English ('en'). But for some reason, the default locale in my app is 'zh-tw'. I see that this used to be an issue (see here and here), but it...

Get Diffrence between two date string in momentjs?

javascript,jquery,angularjs,momentjs,date-difference
I am using momentjs for date and I have one date string, ie,"2015-05-10",I want to get date difference from today var today= moment().format('YYYY-MM-DD'); How it is possible here?...

Momentjs returning different results on firefox compared to chrome

javascript,momentjs
Just by typing out this line on firefox and chrome moment("September 2015") < moment("September 2015").endOf('month') I get true on chrome and false on firefox, how can i make the result be more consistent?...

How to calculate Number of 'Working days' between two dates in Javascript using moment.js?

javascript,date,formula,momentjs
How to calculate the number of working days between two dates in JavaScript using moment.js. I have a working formula that calculate these days, but the formula does not satisfies all conditions: here is my code: var start= moment(data[x].start_date); var end= moment(data[x].est_end_date); var difference= end.diff(start, 'days'); var workingDays= Math.round((difference/7)*5); //data[x]...

how to convert date to day of week using momentjs and angularjs

angularjs,momentjs
I have dates in this format in my json "26 Feb 2015 00:00:00" which I would like to be converted to day of the week ie Tue This seems straightforward using momentjs but my question is how to call the momentjs format() method inside html vs. inside the <script> I...

Is there a way to make moment.js output “1 day” instead of “a day”?

momentjs
I'm using the Time to X function of Moment.js. When the second parameter is true, then the result is a day. Is there a way to make this 1 day through the API, or will I need to do a string replace?

Sorting dates with moment.js does not work when date is a link

datatables,momentjs
I'm using DataTables 1.10.5. When I'm trying to sort on dates using the recommended moment.js (as per http://datatables.net/blog/2014-12-18), thinks work fine: http://jsfiddle.net/9gohzd9t/1/ However, when I add a link (a href) to that date, it sorts on the link instead of the date: http://jsfiddle.net/dnsL2oc4/1/ Any idea on how to properly fix...

DD/MM/YYYY Date format in Moment.js

javascript,angularjs,momentjs
How can i change the current date to this format(DD/MM/YYYY) using moment.js? I have tried below code. $scope.SearchDate = moment(new Date(), "DD/MM/YYYY"); But it's return 0037-11-24T18:30:00.000Z. Did't help to format current date. ...

Js moments timezone

javascript,momentjs
I have the following code to manipulate the time in copenhagen. I was wondering how i would be able to implement this using js moment? function startTime() { var today=new Date(); var i=today.getHours(); var h = i-2; var m=today.getMinutes(); var s=today.getSeconds(); m = checkTime(m); s = checkTime(s); document.getElementById('localtime').innerHTML = h+":"+m+":"+s;...

How do I get chrome to use a time value in an html form?

google-chrome,meteor,momentjs
I am using momentjs LT(local time) and L(local Date) in a meteor app to set the current time and date value in an html form. It is working in Firefox, but in chrome i am getting --:-- -. Does chrome not support type="time" with a value, or am i setting...

Using moment.js to convert time (HH:mm:ss) to (HH:mm)

javascript,jquery,momentjs
I was wondering if I could use moment.js to convert an sql TIME (HH:mm:ss) to just HH:mm. Or maybe there is a simple JavaScript/jQuery solution to this?

Format datetime to YYYY-MM-DD HH:mm:ss in moment.js

datetime,momentjs
I have a string in this format: var dateTime = 06-17-2015 14:24:36 I am using moment.js and I am trying to convert it into YYYY-MM-DD HH:mm:ss = 2015-06-17 14:24:36. I have tried this method dateTime = moment( dateTime, 'MM-DD-YYYY HH:mm:ss',true).format("YYYY-MM-DD HH:mm:ss"); But getting dateTime as Invalid Date....

MomentJS get the previous friday

javascript,momentjs
I have a user inputted date which I convert to a moment var newDate = moment('01/02/2015'); What I need to do is get the previous friday relative to whatever date is passed in. How can I accomplish this? I thought about doing something like this: moment('01/02/2015').add('-1', 'week').day(5); but wonder how...

moment.js - isBetween() method doesn't work consistently

javascript,node.js,date,momentjs
I have a moment.js code that works well: var startDate = '2015-05-06T19:00:00+0300'; moment(startDate).isBetween(moment(), moment().add(30, 'days')); // returns true, that's great! But when I start refactoring to make it more readable it fails to work: var today = moment(); var startDate = '2015-05-06T19:00:00+0300'; moment(startDate).isBetween(today, today.add(30, 'days')); // returns false.. but why?...

How to understand zone by MOMENT.js

javascript,momentjs
I have problem with String > Format of timezone. I have string: " 2015-02-10 00:00:00,3,UTC " And try to format it in moment: moment('2015-02-10 00:00:00,3,UTC', 'YYYY-MM-DD HH:mm:ss, ?, ?') What should I insert instead of "?"...

How to do i correctly use fromNow(), momentjs expression in meteor?

javascript,meteor,momentjs
It shows the correct amount of time when i add the following code. When I refresh the page amount of time is 2015 years. 'dob': is a string like "2015-03-10". var diffInDays = moment(Session.get('dob'), 'YYYY-MM-DD').fromNow(true); Template.registerHelper('daysSinceBirth', function(input) { return diffInDays }); In html template I have {{dob}}....

Express redirect based off URL

node.js,express,momentjs
I'm using Express & Node.js. router.get('/:year?/:month?/:day?', function(req, res) { var date = moment(); if (req.params.year && req.params.month && req.params.day) { var dateString = req.params.year + " " + req.params.month + " " + req.params.day; var tempDate = moment(dateString, "DD MM YYYY"); if (tempDate.isValid()) { date = tempDate; } } .catch(function...

How to Perform Substraction between 2 Times in MomentJs?

momentjs
Iam trying to perform Subtraction in Momentjs:- // Find the duration between two dates var breakfast1 = moment('11:32','HH:mm'); var lunch1 = moment('12:52','HH:mm'); alert( moment.duration(lunch1 - breakfast1).humanize() + ' between meals' ); // 1 hours between meals Output is alerting Only Hours .But How can I get "01:20"as Output Instead of...

Moment Timezone : I don't understand how default timezones work

javascript,timezone,momentjs
Say it's 10:00am in my local time, America/Denver. When I set the default timezone in moment timezone: moment.tz.setDefault("America/Chicago"); Current time objects are printed out in the correct timezone, America Chicago: moment().toString(); // returns 11:00am However, when I parse in a date, for example: // exampleTime equal to 9:05am, already in...

How to load time zone data into Moment-timezone.js

javascript,timezone,momentjs
I'm struggling to get the timezone data loaded for use by moment-timezone.js. Below is my code (For brevity, I only added 2 zones, but really need to add a lot more): <script src='/js/jquery-1.11.0.min.js' type='text/javascript'></script> <script src="/s/js/moment.js" type="text/javascript"></script> <script src="/s/js/moment-timezone.js" type="text/javascript"></script> <script src="/s/js/moment-timezone-with-data-2010-2020.js" type="text/javascript"></script> <script> moment.tz.add([...

AngularJS - Unit tests on Controller that uses moment.js

angularjs,unit-testing,jasmine,momentjs
I'm trying to make unit tests for a controller that uses moment.js to handle three dates of a week. My testing framework is jasmine and my AngularJS version is v1.3.15 Basically I have an init() function that sets them and I want to check if all of them are properly...

Formatting moment from military time to am/pm

momentjs
I'm having a bit of difficulty with some of my moment formatting. From the database I'm getting back a string of 1-24 (military time) and I'm trying to use moment to format this (1am-12am) changing it from military time to a more legible one. I have been playing with this...

Understanding momentjs timezones

javascript,timezone,momentjs
I'm using momentjs in my project. To get the current date and time in a given format I'm using this: moment().format('ddd, D MMM HH:mm'); // Tue, 12 May 12:01 If I output this and view in my browser, I see Tue, 12 May 12:01. I'm currently in London which is...

Get days left till end of the month with moment.js

javascript,momentjs
I want to display or hide a link depending on whether there are less than 2 weeks left in the month, using moment.js, but I'm not sure the correct way to go about it. Currently I have... if (moment().endOf('month')<=(13, 'days')) { //do link stuff here } ...but I don't think...

Moment js is not giving days properly

javascript,angularjs,momentjs
I am using angular with moment js to get date difference but it is not giving right number of days, module.controller("MainCtrl", ['$scope', '$mdDatePicker', function($scope, $mdDatePicker) { this.startDate = function(ev) { $mdDatePicker(ev, $scope.startDate).then(function(selectedDate) { $scope.startDate = selectedDate; var now = selectedDate; var then = $scope.endDate; var ms = moment(now, "DD/MM/YYYY HH:mm:ss").diff(moment(then,...

impossible to convert a date more than three weeks with momentjs

fullcalendar,momentjs
I am trying to use the plugin js calendarfull initialized and I would like the calendar. and then stored in the db. as I receive a date in FR, at first I call into IN with momentjs like this: moment(new Date("01/05/2015")).format("YYYY-DD-MM") it returns me well : 2015-01-05 Now if I...

php dateformat to moment js format

javascript,php,momentjs
I have got a config for php dateformats 'dateFormat' => 'd.m.Y', 'timeFormat' => 'H:i', 'dateTimeFormat' => 'd.m.Y H:i', But for the datetimepicker i need moment.js formatting (http://momentjs.com/docs/#/displaying/format/) that will look like so: DD.MM.YYYY HH:mm DD.MM.YYYY HH:mm This would be no problem for me to replace d with DD and m...