Menu
  • HOME
  • TAGS

Define DateTime Formats and Convert One to another Using Momentjs

javascript,momentjs

Try this. You can format it later by checking moment.js docs. var moment = require('moment'); var date = new Date('Sun Jun 28 2015 06:00:00 GMT-0400') var a = moment(date).format('L hh:mm A'); console.log(a); ...

Get Diffrence between two date string in momentjs?

javascript,jquery,angularjs,momentjs,date-difference

here is a example, var now = moment(); // moment object of now var day = moment("2015-05-13"); // moment object of other date $scope.difference = now.diff(day, 'days'); // calculate the difference in days $scope.difference = now.diff(day, 'hours'); // calculate the difference in hours check more options here here is a...

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

javascript,momentjs

If at all possible, you should keep the value in UTC until you're ready to format. Timezone, along with date format, is generally part of localization and not something you want embedded too deeply in your business logic. Do note that there have been timezones that changed their local flow...

Create moment Object from UTC string

javascript,date,momentjs,utc

You're just hitting a bug, already logged as #2367. Stated very simply, it's using the last locale loaded ("zh-tw"), rather than defaulting to English. Simply call add the following line after you load moment but before you use it anywhere. moment.locale('en'); This sets the language back to English. That explains...

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

javascript,fullcalendar,momentjs,spip

Well, I found out how to do it. Step 1: Get the languages. Go to the locale directory of moment.js on github and download the languages you need. I took de.js, en.js & fr.js. Step 2: Upload them to your server. I made a new folder in the FullCalendar directory...

fromNow displays different strings on different browsers

javascript,timezone,momentjs

You are creating the moment from a String, and it is not recommended: Warning: Browser support for parsing strings is inconsistent. Because there is no specification on which formats should be supported, what works in some browsers will not work in other browsers. For consistent results parsing anything other than...

php dateformat to moment js format

javascript,php,momentjs

So i wrote a litte helper function to convert the php dateformats into the format needed for moment.js function convertPHPToMomentFormat($format) { $replacements = [ 'd' => 'DD', 'D' => 'ddd', 'j' => 'D', 'l' => 'dddd', 'N' => 'E', 'S' => 'o', 'w' => 'e', 'z' => 'DDD', 'W' =>...

Parsing Apache Log Timestamps with JavaScript

javascript,mysql,apache,momentjs

You need to tell moment what format the string is in so it can parse it. Something like: moment( '08/Jun/2015:15:03:29', 'DD/MMM/YYYY:HH:mm:ss Z').format("YYYY-MM-DD HH:mm:ss") ...

Convert time to DateTime using moment js

jquery,momentjs

You need to use string-format moment constructor to pass string and format in which input string is. Use var t = "13:56"; var cdt = moment(t, 'HH:mm'); alert(cdt.toDate()); alert(cdt.format('YYYY-MM-DD HH:mm')) <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.js"></script> ...

Moment .isAfter not returning correctly

javascript,momentjs

Even though the first date string is utc, you still need to put the moment into utc mode before you compare. Take a look at the docs here: http://momentjs.com/docs/#/parsing/utc/ //String is already in utc time, but still need to put it into utc mode var active_time = moment.utc('2015-06-04T15:00Z', 'YYYY-MM-DD[T]HH:mm[Z]'); //Convert...

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

javascript,datetime,momentjs,date-formatting

Try this, var Months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] var dt = new Date(1425935535000+0000); var sFinalDate = dt.getDate() + " " + Months[dt.getMonth()] JSFIDDLE: http://jsfiddle.net/ed3qavuj/...

Moment.js difference between flight departure and arrival

javascript,momentjs

You should use moment.duration to deal with durations here. 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()); var duration = moment.duration(arrival.diff(departure)); console.log("duration: " + duration.humanize()); ...

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

javascript,momentjs

Consider: // keep this as a moment, and use noon to avoid DST issues var currentDate = moment().startOf('day').hour(12); ... // parse the property at noon also var m = moment(prop + "T12:00:00"); // diff the current date (as a moment), against the specific moment console.log(currentDate.diff(m, 'days') > 3); I've also...

MomentJS get the previous friday

javascript,momentjs

newDate.day(-2); It's that easy. :) day() sets the day of the week relative to the moment object it is working on. moment().day(0) always goes back to the beginning of the week. moment().day(-2)goes back two days further than the beginning of the week, i.e., last Friday. Note: this will return to...

How to display dates in my app without excessive load?

meteor,momentjs

Dates are not reactive by themselves, so you need to include a reactive data source in your helper to force it to rerun. In this example, we'll update a session variable that will force all instances of postedTime to be reevaluated every 60 seconds: Template.registerHelper('postedTime', function(date) { Session.get('timeToRecompute'); return moment(date).fromNow();...

How to set a default offset in Moment.js?

javascript,momentjs

I would probably do something like: var offsetMoment = (function(){ var globalOffset = moment.duration(); // Defaults to no offset var offsetMoments = []; // Stores all moments that have a global offset var throwIfNotOffsetMoment = function(moment){ // Regular moment objects can't use offset methods if(! moment.isOffsetMoment){ throw "- Moment is...

moment.js doesn't parse time from timestamp

javascript,angularjs,momentjs

Well, this took me longer than it should have... dt.startOf('day') modifies dt, it doesn't clone. moment().startOf(String); Mutates the original moment by setting it to the start of a unit of time. So use clone(): if(dt.clone().startOf('day').isSame(today)) return dt.format('[Today], H:mm:ss'); if(dt.clone().startOf('day').isSame(yesterday)) return dt.format('[Yesterday], H:mm:ss'); Or use some other method that doesn't modify...

Moment with Timezone not properly formatting date

momentjs

Your code looks correct, and it works when testing in the Chrome dev tools debugger console while on the moment-timezone website: Here's a working snippet: var a = moment('2014-10-03T23:09:42.764Z').tz('Europe/Paris').format(); var b = moment('2014-10-03T23:09:42.764Z').tz('Europe/London').format(); document.getElementById("a").innerHTML = a; document.getElementById("b").innerHTML = b; <script src="http://momentjs.com/downloads/moment.min.js"></script> <script...

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

momentjs

You can use the string.replace method to replace a day with 1 day. Or you can try like this: var a = moment([2007, 0, 29]); var b = moment([2007, 0, 28]); var differenceInMillisec = a.diff(b); var differenceInDays = a.diff(b, 'days'); //Output 1 day ...

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

javascript,date,timezone,momentjs,utc

Just use the .local() function, added in version 1.5.0. var localDate = moment.utc(utcDateStr, 'YYYYMMDDHHmmss').local(); ...

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

jquery,bootstrap,momentjs,bootstrap-datetimepicker

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 this fiddle for examples to get you started http://jsfiddle.net/spasticdonkey/9Lnbp7pw/3/ $('#datetimepicker1').on('dp.change', function (e) { var kk = $("#datepicker").val(); $("#output").html( "Week Number: " + moment(kk, "DD/MM/YYYY").week() + "...

How to find a specific time milliseconds in javascript?

javascript,javascript-library,momentjs

To get timestamp in milliseconds var todaydate = new Date(); var millisecondTimestamp = Date.parse(todaydate); JSFiddle...

Angular Bootstrap DateTimePicker - Highlight Today Date on embedded Calender

angularjs,datetimepicker,momentjs,angular-bootstrap

To get the directive to show todays date by default, you can set the value of data.embeddedDate in the controller through it's scope, like so: $scope.data = { embeddedDate: new Date() }; Working Plunkr...

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

angularjs,momentjs

Here's a custom filter that wraps moment().format() angular.module('myApp', []) .controller('myCtrl', function($scope) { $scope.myDate = '28 Feb 2015 00:00:00 GMT'; }) .filter('format', function() { return function(input, format) { return moment(new Date(input)).format(format); }; }) ; <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script> <div ng-app="myApp"...

Momentjs returning different results on firefox compared to chrome

javascript,momentjs

From the momentjs docs http://momentjs.com/docs/#/parsing/now/ Browser support for parsing strings is inconsistent. Because there is no specification on which formats should be supported, what works in some browsers will not work in other browsers. For consistent results parsing anything other than ISO 8601 strings, you should use String + Format....

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

javascript,date,momentjs

I think need to figure out the logic better - perhaps this can be condensed but here is a full if block containing all possible conditions that you'd need to flesh out. if(todayDate.isAfter(firstPayment)) { if (todayDate.isBefore(secondPayment)) { lastInterestPaymentDate.text(firstPayment.add(-1,'years').format('DD MMM YYYY')); nextInterestPaymentDate.text(secondPayment.format('DD MMM YYYY')); } else if (todayDate.isAfter(secondPayment)) { // ??...

Date String conversion in Python and momentjs

python,momentjs

How about >>> arrow.get(timezone='UTC') <Arrow [2015-03-08T18:42:06.629114+00:00]> >>> str(arrow.get()) '2015-03-08T18:42:08.645550+00:00' >>> arrow.get(tz='UTC').format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z' '2015-03-08T18:47:35.205Z' ...

isSame() function in moment.js or Date Validation

javascript,validation,date,momentjs

Docs - Is Same Check if a moment is the same as another moment. moment('2010-10-20').isSame('2010-10-20'); // true If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter. moment('2010-10-20').isSame('2009-12-31', 'year'); // false moment('2010-10-20').isSame('2010-01-01', 'year'); // true moment('2010-10-20').isSame('2010-12-31', 'year'); // true moment('2010-10-20').isSame('2011-01-01',...

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

javascript,node.js,date,momentjs

var today = moment(); var startDate = '2015-05-06T19:00:00+0300'; moment(startDate).isBetween(today, moment(today).add(30, 'days')); You are passing a reference which you have edited by adding 30 days....

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

javascript,c#,momentjs,utc

You can print an UTC ISO 8601 date for moment with ToString("s") but it will lack the Z, so you need to add it yourself. var localTime = moment('@String.concat(Model.Invoice.InvoiceDate.ToString("s"), "Z")').format('lll'); Or by adding the Z on client side : var localTime = moment('@Model.Invoice.InvoiceDate.ToString("s")' + 'Z').format('lll');...

impossible to convert a date more than three weeks with momentjs

fullcalendar,momentjs

Don't create the moment instance from a string without specifying the format. It will behave differently on each browser. Instead, use the String + Format constructor: moment("01/05/2015", "DD/MM/YYYY").format("YYYY-DD-MM"); // => '2015-01-05' moment("30/05/2015", "DD/MM/YYYY").format("YYYY-DD-MM"); // => '2015-30-05' From moment.js docs: Warning: Browser support for parsing strings is inconsistent. Because there is...

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

javascript,momentjs

You could do something like this: var a = moment().endOf('month'); var b = moment().today; if(a.diff(b, 'days') <= 13) { //do something } ...

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

javascript,angularjs,momentjs,angular-moment

If you are using Angular, usually what works for me is this .run(["moment", function(moment){ moment.locale("en"); }]); ...

Datetime in MST Zone

javascript,c#,asp.net-mvc,angularjs,momentjs

If you send the timestamp to the client and you are using momentjs, then it's pretty simple var day = moment(TS_IN_MILLISECONDS).tz('America/Denver') With the string you provided, you can do this: var UTCTime = moment.utc('2015-04-22 18:43:18.967').toDate(); var MSTTime = moment(UTCTime).tz('America/Denver').format('YYYY-MM-DD HH:mm:ss'); ...

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

javascript,angularjs,html5,momentjs

As per statement even momentjs is also gives error to convert this format of date, I have taken liberty and used momentjs here. You need to use string-format moment constructor to pass string and format in which input string is. Use var t = "27.05.2015 01:46:32.UTC"; //pass dateTime string and...

Understanding momentjs timezones

javascript,timezone,momentjs

Yup, that should work: var now = new Date(); snippet.log("Default: " + moment(now).format('ddd, D MMM HH:mm z')); snippet.log("Europe/London: " + moment(now).tz('Europe/London').format('ddd, D MMM HH:mm z')); snippet.log("America/New_York: " + moment(now).tz('America/New_York').format('ddd, D MMM HH:mm z')); <script src="http://momentjs.com/downloads/moment.js"></script> <script src="http://momentjs.com/downloads/moment-timezone-with-data-2010-2020.js"></script> <!-- Script provides the `snippet` object, see...

DD/MM/YYYY Date format in Moment.js

javascript,angularjs,momentjs

You need to call format() function to get the formatted value $scope.SearchDate = moment(new Date()).format("DD/MM/YYYY") //or $scope.SearchDate = moment().format("DD/MM/YYYY") The syntax you have used is used to parse a given string to date object by using the specified formate...

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

javascript,angularjs,recursion,angularjs-directive,momentjs

Instead of using setInterval, you need to use the Angular wrapper service $interval. $interval service synchronizes the view and model by internally calling $scope.$apply which executes a digest cycle....

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

javascript,timezone,momentjs

You have loaded moment-timezone twice, and loaded data twice. It's probably getting confused. <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"> Both of the above statement load the moment-timezone code. You should only have one of them. If you are loading specific zones using moment.tz.add, then you should use the moment-timezone script....

how to convert milliseconds to Relative time?

jquery,date,momentjs

Try: moment(new Date(1423554515215)).fromNow() Gives "36 minutes ago" right now....

Momentjs start of day off by 4 minutes?

javascript,google-chrome,google-chrome-devtools,momentjs

Because MM in HH:MM:ss refers to the two digit month (see docs for format()). And we are currently in April. :-) Try mm instead....

AngularJS - Unit tests on Controller that uses moment.js

angularjs,unit-testing,jasmine,momentjs

You shouldn't pass currentDate back in to the moment creation function. Doing so will invoke parsing, will fall back to the browser's implementation (giving you a deprecation warning), and will fail if the browser's locale is not the same as the one you formatted. Either just call moment() each time:...

Grouping using timestamp in ng-repeat

angularjs,momentjs

You could create a groups array in your controller and use a filter function to filter the tasks into groups. I created this fiddle with an example. The javascript: (function() { angular .module('TaskApp', ['angularMoment']) .controller('TaskController', TaskController); function TaskController($scope) { $scope.groups = [ { name: "Due Today", value: { from: 0,...

How to Perform Substraction between 2 Times in MomentJs?

momentjs

.humanize() will always round to a specific interval. Break your code up and manually create the display you want... var breakfast1 = moment('11:32','HH:mm'); var lunch1 = moment('12:52','HH:mm'); var dur = moment.duration(lunch1 - breakfast1); alert( dur.hours() + ":" + dur.minutes() + ' between meals' ); ...

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

javascript,angularjs,date,momentjs

There is some problem with date format you are passing. So it would also work if you just remove the format and just pass in the value. Run and check the code snippet below its working fine var validateDateRange = function (fromDate, toDate) { var fromDate = moment(fromDate); var toDate...

Deprecation warning: moment construction falls back to js Date

javascript,momentjs

You need to tell moment how to parse your date format, like this: var parsedDate = moment.utc("150423160509", "YYMMDDHHmmss"); var a = parsedDate.tz("Asia/Taipei"); // I'm assuming you meant HH:mm:ss here console.log( a.format("YYYY-MM-DD HH:mm:ss") ); ...

Formatting moment from military time to am/pm

momentjs

You can use: moment("16", "hh").format('hA') ...

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

javascript,node.js,momentjs,iso

You need to use moment.duration function. Also, to get the total value in seconds, use asSeconds() instead of seconds(). In your case: var moment = require('moment'); var duration = 'PT15M51S'; var x = moment.duration(duration, moment.ISO_8601); console.log(x.asSeconds()); // => 951 ...

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

javascript,jquery,google-chrome,date,momentjs

The problem you are facing is most likely caused by the fact, that different browser (engines) implement different algorithms for sorting. The differences you experience are (at first glance) all focused on elements that have no difference (e.g. 0 returned from your sort-function) and thus have no deterministic sort-behavior described....

moment.js: convert timestamp and show month in German

javascript,momentjs

You have the unix constructor AFTER you are defining a locale.. So you're defining a locale onto nothing. You need to create the moment first before defining a locale. So moment will be created from the .unix() method, and from this returned result, you can define a locale onto it....

Abbreviated relative time (Instagram style) using momentjs?

javascript,datetime,momentjs

You can define custom locale strings. moment.locale('en', { relativeTime : { future: "in %s", past: "%s ago", s: "seconds", m: "a minute", mm: "%d minutes", h: "an hour", hh: "%d hours", d: "a day", dd: "%d days", M: "a month", MM: "%d months", y: "a year", yy: "%d years" }...

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

javascript,jquery,date,math,momentjs

I would create an new array and fill in the voids, something like this var dates = []; for (var i=0; i<data.length; i++) { var now = data[i], thisStart = parseDate(now.start), thisEnd = parseDate(now.end), prevEnd = data[i-1] ? parseDate(data[i-1].end) : null; if ( prevEnd && prevEnd <= thisStart ) {...

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

javascript,meteor,momentjs

I am unable to comment because I dont have enough reputation. So posting it here. Try this: Template.registerHelper('daysSinceBirth',function(dob){ if(moment && dob){ return moment(dob).fromNow(); } else { return dob; } }); In the template use {{daysSinceBirth dob}}....

Moment js is not giving days properly

javascript,angularjs,momentjs

You don't need to use duration for this. Directly use the second parameter of diff to get the difference as days : $scope.dateDifferenceDays = moment(now, "DD/MM/YYYY HH:mm:ss").diff(moment(then, "DD/MM/YYYY HH:mm:ss"), 'days'); ...

How to understand zone by MOMENT.js

javascript,momentjs

It's not possible to format that kind of string into moment because a lone 3 does not designate the timezone offset in any standard format. You need to change the 3 into +0030. This should work: var date = '2015-02-10 00:00:00,3,UTC' .replace(/,(\d\d),/,',+$100,') // for double digit cases (11 turns to...

How do I use two different relativeTime customizations?

momentjs

I think the answer centres around what is documented here In short, tweak part of the locale to suit your needs using a function. Here is a short sample: var useshort = false; moment.locale( 'en', { relativeTime : { future: "in %s", past: "%s ago", s: "seconds", m: function (/*...

Js moments timezone

javascript,momentjs

You'll need the timezone plugin if you want specific timezones. Otherwise you can leave it out. Provides .tz() function startTime() { //local time document.getElementById('localtime').innerHTML = moment().format('hh:mm:ss'); //copenhagen timezone document.getElementById('copenhagen').innerHTML = moment.tz('Europe/Copenhagen').format('hh:mm:ss'); var t = setTimeout(function(){startTime()},500); } <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/moment-with-locales.js"></script> <script...

Date not binding with model for specific culture

jquery,asp.net-mvc,datetime,momentjs,globalization

Default model binder in asp.net mvc is aware of date localization issues. To make it parse date in specified culture, you need to set CurrentCulture before action method is called. I am aware of few possible ways to do this. Globalization element Globalization element can automatically set CurrentCulture to user's...

Add locale moment to an AngularJS app

angularjs,gruntjs,momentjs

You should insert it outside the bower section, like this: <!-- build:js(.) scripts/vendor.js --> <!-- bower:js --> <script src="bower_components/jquery/dist/jquery.js"></script> <script src="bower_components/angular/angular.js"></script> <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script> … <script src="bower_components/angular-loading-bar/build/loading-bar.js"></script> <script...

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

javascript,internationalization,momentjs

In short, you cannot using localMoment. A moment object returned by a called to moment() does not have a duration function (whether you set a specific locale or keep the default). The duration functionality belongs to the module itself (the 'object' returned by the require call). It was designed this...

Get the last week date in Javascript

javascript,vb.net,date,momentjs

this is easy to do with MomentJs function SetLastWeekDate(sender, args) { var lastWeekDate = $find("<%=btnTimeOfDayLastWeek.ClientID %>"); var fromDate = $find("<%=rdpTimeOfDayFrom.ClientID %>"); var toDate = $find("<%=rdpTimeOfDayTo.ClientID %>"); var today = moment(); if (lastWeekDate.get_checked()) { fromDate.clear(); toDate.clear(); var lastWeekPeriod = moment().subtract(7, 'd').format("YYYY/MM/dd"); fromDate.set_selectedDate(lastWeekPeriod); toDate.set_selectedDate(today); } } if you can set the local...

Express redirect based off URL

node.js,express,momentjs

I looked through your code and it looks really inconsisten and I don't fully understand what you're trying to do, but you can probably narrow it down to something like this: router.get('/:year?/:month?/:day?', function (req, res) { var year = req.params.year; var month = req.params.month; var day = req.params.day; if (year...

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

meteor,momentjs

I think the moment package on Atmosphere is actually up to 2.9.0. Try either running a meteor update, or manually remove the moment package (meteor remove momentjs:moment) and re-adding it. Also, you shouldn't need to use new moment(), just moment(), like this: var today = moment().format('MM/DD/YYYY'); ...

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

javascript,momentjs

Maybe it would be easiest to wrap your date parsing in another function that attaches metadata to the result. Here's a rough idea: function parseDate(d) { var ret = moment(d); if(d.indexOf('-') === -1) { ret.monthOnly = true; } return ret; } ...

Serializing dates in moment.js

javascript,momentjs

Best solution is to store as milliseconds since epoch... var ms = moment().valueOf(); ...then you can easily restore by passing that value into the moment constructor... var dt = moment(ms); ...

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

datatables,momentjs

The problem lies in the unshift method of datetime-moment.js. Moment tries to convert <a href="12.html">12-01-2001</a> to a valid date in the given "DD-MM-YYYY"-Format, which it can't obviously. So you have to strip the html away from the date, probably with a function like this: function strip(html) { var tmp =...

Showing update time like Twitter's update notification

javascript,momentjs

If you want to make the diff between 2 dates in seconds : moment().diff(mydate, 'seconds')

Date and time without timestamp in Javascript

javascript,date,jodatime,momentjs,datejs

I've started a few times on a JavaScript library with similar API to Noda Time / Joda Time / Java 8. I definitely see value in that. However, there's nothing out there as of yet, as far as I know. There are other reasons that make the Date object less...

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

datetime,momentjs

Try this. You should have the date in the correct format. var dateTime = new Date("2015-06-17 14:24:36"); dateTime = moment(dateTime).format("YYYY-MM-DD HH:mm:ss"); ...

How to get a specific date format using momentjs?

javascript,date,calendar,momentjs

You can't really "roll your own" when it comes to localized dates because every locale has its own set of localized date strings. This is because different countries display their dates differently. Why don't you want to use a country's format? If someone from another country uses your site, they...

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

javascript,timezone,momentjs

You're using it correctly, you're just hitting on a bug. It's already been logged in this issue, and there's a pending fix here.

Momentjs : How to prevent “Invalid date”?

javascript,momentjs,invalidate

TL;DR If your goal is to find out whether you have a valid date, use Moment's isValid: var end_date_moment, end_date; jsonNC.end_date = jsonNC.end_date.replace(" ", "T"); end_date_moment = moment(jsonNC.end_date); end_date = end_date_moment.isValid() ? end_date_moment.format("L") : ""; ...which will use "" for the end_date string if the date is invalid. Details There...

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

javascript,datetime,meteor,timezone,momentjs

Good news! You're overcomplicating it :-) Open up a browser console & type time = new Date(). Notice how it's in the correct timezone? That's because the timezone conversion is happening on the client. Now, type time.valueOf(). As you probably know, you've got the number of milliseconds since 1-1-1970...but in...

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

javascript,date,momentjs

Here's something that can be useful: var REFERENCE = moment("2015-06-05"); // fixed just for testing, use moment(); var TODAY = REFERENCE.clone().startOf('day'); var YESTERDAY = REFERENCE.clone().subtract(1, 'days').startOf('day'); var A_WEEK_OLD = REFERENCE.clone().subtract(7, 'days').startOf('day'); function isToday(momentDate) { return momentDate.isSame(TODAY, 'd'); } function isYesterday(momentDate) { return momentDate.isSame(YESTERDAY, 'd'); } function isWithinAWeek(momentDate) { return momentDate.isAfter(A_WEEK_OLD);...

moment.js 2 digit year converting wrong 4 digit year

javascript,jquery,momentjs

When you throw a random string into moment without telling it what format it's in, it falls back on the JavaScript Date object for parsing, and the format you're passing in is not defined by the standard. That leaves you wide open to implementation-specific behavior. In this case, what you...

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

javascript,jquery,momentjs

Yes, you can: moment('12:59:01', 'HH:mm:ss').format('HH:mm') Or, if the format is consistent, you could just chop the last 3 chars: '12:59:01'.slice(0, -3) ...

Update relative time with MomentJS

javascript,time,momentjs

You don't save the moment but a string. If you want to keep using that string, you must parse it: var rel = moment(tObj.timeClicked,["dddd, MMMM Do YYYY, h:mm:ss a"]).fromNow(true); Of course it would be simpler to store the moment itself : http://codepen.io/anon/pen/qdOjqr...

format end date of time span using momentjs

javascript,localization,momentjs

Moment doesn't currently have support for a 24th hour. Midnight is always the 0'th hour at the beginning of the day. Other than that, you can get the format you're asking about by combining the short-date locale format specifier with the time-locale specifier. For example: moment.locale('de'); moment("2015-12-31T13:45").format('l LT') // "31.12.2015...

Loading web-page with moment in electron

momentjs,electron

Creating the BrowserWindow with the flag 'node-integration' set to false, seems to do it. browser = new BrowserWindow({ 'node-integration': false, width:800, height:600, }) ...

Format Moment.js Duration

javascript,momentjs

One way of doing this might be to convert your duration back into a moment (perhaps using milliseconds), and then using the moment's formatting. moment(span.asMilliseconds()).format('mm:ss.SSS'); var startMoment = null, $durForm = $('#durationFormatted'); var actionClock = null; function startClock() { actionClock = setInterval(function() { if (startMoment === null) { startMoment =...

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

javascript,jquery,angularjs,date,momentjs

You could pass in 2 dates from your server: the existing timestamp, and the server's "now" timestamp. Then (assuming your server passes in its timestamp in the same format) you can use .from() instead of .fromNow() do: moment(time, "YYYY-MM-DD HH:mm:ss.SSSSSS").from(serverTime, "YYYY-MM-DD HH:mm:ss.SSSSSS"); If this is the only thing you're using...

One month from today with momentjs

javascript,momentjs

You need to use .format() method with 'MM/DD/YYYY' as parameter alert(moment().add(1, 'months').format('MM/DD/YYYY')); <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.js"></script> ...

moment.js multiple live clocks using one function

javascript,jquery,momentjs

Problem was the selector of element children, It works perfectly now by changing: $(this).next('.hero-*') To be like this: $(this).find('.hero-*') Thanks to Scott Hunter for the hint....

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

javascript,jquery,momentjs

Use setInterval() to run the code every 60 seconds. Use html() instead of append() so that the previous time is overridden. function updateTime(){ var newYork = moment.tz("America/New_York").format('HH:mm a'); $('#time').html( "Current time in New York: "+newYork ); }; moment.tz.add('America/New_York|EST EDT|50 40|0101|1Lz50 1zb0 Op0'); updateTime(); setInterval(function(){ updateTime(); },60000); http://jsfiddle.net/93pEd/135/ Heres an example...

Convert JSON.NET date to jQuery UI Datepicker format

jquery,jquery-ui,datepicker,momentjs

Using the moment.js library for formatting date, substitute moment(BoardStart).format('MM/DD/YYYY') with moment(BoardStart, "YYYY-MM-DDhh:mm:ss").format("MM/DD/YYYY") ...

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

javascript,ember.js,timezone,momentjs

You need to import Moment before importing Moment Timezone. See http://momentjs.com/timezone/docs/...

Full calendar Timezone Moment js Issue

javascript,timezone,fullcalendar,momentjs

FullCalendar's time zone documentation explains that named time zones are expected to be calculated on the server. While it supports tagging events with a time zone, it doesn't do any time zone conversion on the client-side. Unless this behavior changes in a future release, it doesn't fit the scenario you...

Date time difference in moment.js

javascript,angularjs,local-storage,momentjs

moment() returns an object, the local storage doesn't accept object. Parse into string before store the value $scope.SetLocalStorage('My-' + $rootScope.UserId, JSON.stringify(moment())); And when you use it use JSON.parse : var dt = moment(JSON.parse($scope.GetLocalStorage('My-' + $rootScope.UserId))); ...

Displaying inaccurate date using moment.js

jquery,node.js,momentjs

@MattJohnson - suggested formatting the date instead of parsing.

Time zone conversions

javascript,date,timezone,momentjs

These are your original values: Start Date: "2015-02-19T00:00:00-08:00" End Date: "2015-02-19T17:00:00-08:00" These are the equivalent values in UTC: Start Date: "2015-02-19T08:00:00+00:00" End Date: "2015-02-20T01:00:00+00:00" These are the equivalent values in Indian Standard Time: Start Date: "2015-02-19T13:30:00+05:30" End Date: "2015-02-20T06:30:00+05:30" This is normal and expected behavior when adjusting time for time...

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

javascript,date,momentjs

You'll want to modify your now variable after each diff. var hours = mid.diff(now, 'hours'); //Get hours 'till end of day now.hours(now.hours() + hours); var minutes = mid.diff(now, 'minutes'); ...

Moment JS Returning Incorrect Value

javascript,node.js,momentjs

Just to clarify zerkms answer, where you have: thisMonth = moment().utc(tz).month() + 1, you are setting thisMonth to 2 (if run in Feburary), then when you do: start = moment([2015, 1, 31, 15]), you are creating a date for 31 February, which doesn't exist so a date for 3 March...

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

javascript,date,formula,momentjs

Just divide it into 3 parts.. first week, last week and the in between, something like this: function workday_count(start,end) { var first = start.clone().endOf('week'); // end of first week var last = end.clone().startOf('week'); // start of last week var days = last.diff(first,'days') * 5 / 7; // this will always...

How does locale() work regarding timezones?

javascript,momentjs

locale() does not set the timezone, only the language var fr = moment().locale('fr'); fr.locale().months(moment([2012, 0])) // "janvier" fr.locale('en'); fr.locale().months(moment([2012, 0])) // "January" http://momentjs.com/docs/#/i18n/adding-locale/...

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

google-chrome,meteor,momentjs

Chrome expects a 24-hour clock, as in value="13:34" or the like. It also wants a date in YYYY-MM-DD format, like 2015-03-08. So change your helpers to accommodate: Template.registerHelper('date', function(input) { return moment().format('YYYY-MM-DD'); }); Template.registerHelper('time', function(input) { return moment().format('H:mm'); }); See example: http://meteorpad.com/pad/XiZBySYHfEydaaZbb/Input%20date%20and%20time%20test (works for me in Chrome in the U.S....

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

javascript,angularjs,date,momentjs,pikaday

Giving you're already getting time with momentjs, you can try moment.utc() method. The docs say: As of version 2.0.0, a locale key can be passed as the third parameter to moment() and moment.utc() moment('2012 juillet', 'YYYY MMM', 'fr'); moment('2012 July', 'YYYY MMM', 'en'); You can do a lot more with...