Convert HH:mm into Moment.js
moment(’09:00′,’h:mm a’).format(‘h:mm a’);
moment(’09:00′,’h:mm a’).format(‘h:mm a’);
Note my use of t.format comes from using Moment.js, it is not part of JavaScript’s standard Date prototype. A Unix timestamp is the number of seconds since 1970-01-01 00:00:00 UTC. The presence of the +0200 means the numeric string is not a Unix timestamp as it contains timezone adjustment information. You need to handle that … Read more
There is a more popular angular-moment project… https://github.com/urish/angular-moment With it, you can inject moment like this… app.controller(“ctrl”, function($scope, moment) { $scope.date = new moment(); }); Fiddle Or if you don’t need the additional functionality and directives provided by angular-moment, you can make momentjs injectable in your app by using angular.value() or angular.constant() (angular-moment uses constant() … Read more
As you can see, with moment lib, we need 2 steps to get the result: parse string to Date object, then format date object to string. Your code – format(new Date(“10-13-20”), ‘MM-DD-YY’) is format step, try convert a date object to a string with format template is MM-DD-YY. But your date object is not correct. … Read more
According to Moment.js documentation, ‘month’ uses an array and the indices of an array are zero-based. Therefore, January is set to ‘0’ and December is set to ’11’. For example, moment().month(‘November’); prints ’10’.
Use the valueOf method on a moment object: For local time: moment().valueOf(); For UTC: moment().utc().valueOf();
Try using the format (second) parameter moment(“12-25-1995”, “MM-DD-YYYY”); For details see http://momentjs.com/docs/#/parsing/string-format/
This is now supported in moment: moment(‘2014-12-01’).utc().quarter() //outputs 4 moment().quarter(); //outputs current quarter ie. 2 Documentation
There happens to be a function for that: moment.monthsShort() // [“Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”,”Aug”,”Sep”,”Oct”,”Nov”,”Dec”] Or the same using manual formatting: Array.apply(0, Array(12)).map(function(_,i){return moment().month(i).format(‘MMM’)}) I guess you want to display all names utilizing Moment.js locale data, which is a reasonable approach.
moment does parse ISO-formatted durations out of the box with the moment.duration method: moment.duration(‘P1Y2M3DT4H5M6S’) The regex is gnarly, but supports a number of edge cases and is pretty thoroughly tested.