momentjs

How can I convert date time format string used by C# to the format used by moment.js?

那年仲夏 提交于 2020-01-12 06:50:28
问题 C# uses string like that 'dd MMMM yyyy HH:mm' to define format the date and time should be displayed in. Equivalent of that in momentjs is 'DD MMMM YYYY HH:mm' . Is there some function that can covert one format definition into the other regardless of what (legal) combination of format specifiers source format contains? Basically what I want is: function toMomentJsFormatDefinition(cSharpFormatDefinition) { // should convert all format strings described here https://msdn.microsoft.com/en-us

Inserting a momentjs object in Meteor Collection

心已入冬 提交于 2020-01-11 04:38:26
问题 I have a simple Meteor collection and I am trying to insert a document that has a momentjs property into it. So I do: docId = Col.insert({m: moment()}); However, when I try to get this document back with doc = Col.findOne({_id: docId}) I get "Invalid date" for doc.m like so: Object {_id: "wnHzTpHHxMSyMxmu3", m: "Invalid date"} Anyone?! 回答1: I strongly recommend storing dates as Date objects and using moment to format them after they are fetched. For example: Posts.insert({message: 'hello',

Abbreviated relative time (Instagram style) using momentjs language wise dynamic?

风流意气都作罢 提交于 2020-01-07 06:40:20
问题 moment().startOf('day').fromNow() //3 days ago. How can I change the above to show 3d instead of language is English and to "3 j" if language is french and so on dynamically change according to the language? 回答1: You can use moment.locale method as reported in the docs. Remember that you have to import all locales you need or you can use moment-with-locales.js that provides all supported locales. EDIT: To customize format of momentjs fromNow method you can use updateLocale as documented in

Moment.js local relative time

牧云@^-^@ 提交于 2020-01-07 05:29:11
问题 I have dates in my database set to Europe/London time. I am using Moment.js to show relative time e.g. "3 minutes ago". This works fine for me as I am in the same timezone, but for example, someone who is PST timezone would see "in 8 hours". How can I fix this? My current code is like this: $('time').text( moment( '2016-01-22 18:00:00' ).fromNow() ); 回答1: To echo Jon's answer, moment's relative time functionality is strictly UTC based, so the behavior you describe won't actually happen,

.dateParseExact return null

。_饼干妹妹 提交于 2020-01-07 05:23:46
问题 I'm trying to parse the following date: Tue, 27 Oct 2015 00:00:00 GMT this is my code: start = Date.parse(currDateStart.toString('dd/MM/yyyy') + ' ' + workingDay.start, 'dd/MM/yyyy HH:mm'); where currDateStart is the date that I want parse (see above), and working.start contains : 09:00 so the final result should be: Tue, 27 Oct 2015 09:00:00 GMT but instead I get null why? 回答1: Neither moment or Date will accept a format parameter in the toString function. Assuming curreDateStart and the

How to format decimal hours greater than 24 hours into hours minutes in JavaScript

前提是你 提交于 2020-01-07 04:48:08
问题 I have seen many posts about decimal hours to hours:minutes, but I have not found any that work for more than a days worth. I am using the following with moment.js.. function formatHours(decimalHours) { var duration = moment.duration(decimalHours, 'hours'); var hours = duration.hours(); var minutes = duration.minutes(); var date = moment().hours(hours).minutes(minutes); var result = date.format('HH:mm'); return result; } but this does not work for greater than 24 hours,eg I have a hours

Calculate duration between momentjs timestamps in UTC

非 Y 不嫁゛ 提交于 2020-01-07 04:24:09
问题 I am having a hard time to calculate the duration (difference in time) of two timestamps. There is a timestamp I receive from the server in the following format: start # => "2017-05-31 06:30:10 UTC" (This is basically rubys DateTime.now.utc ) I want to see how many hours have passed since then until as of right now. The calculation happens in the angularjs frontend only. I tried the following: var start = moment("2017-05-31 06:30:10 UTC", "YYYY-MM-DD HH:mm:ss Z").utc(); var now = moment.utc()

how to convert, date change event into particular format

落爺英雄遲暮 提交于 2020-01-07 04:19:07
问题 I am having date in my site, and I am using dates using daterangepicker and moment js. Now I am new to all these things & one of the variable setting up date is as moment().subtract(29, 'days') whose console.log results into 1492930351644 , similarly moment() result to 1495435951644 . Now on manual change by the user I want, to update this values but however I don't know how to make use of it. I have used jQuery event as below $('#dateRange').on('apply.daterangepicker', function(ev, picker) {

Get the next time that respect a time format and not a pervious one

断了今生、忘了曾经 提交于 2020-01-07 03:42:49
问题 I am trying to get the time to the next "6:00:00", I am using moment: let shiftEnd = moment("06:00:00", "HH:mm:ss") console.log(shiftEnd.inspect()) It gets me the previous 6:00:00, the one with the same day as now() . moment("2017-07-31T06:00:00.000") now() is: moment("2017-07-31T12:20:57.076") What's the best way to get the next 6am that's not passed yet? 回答1: You are getting a moment object for the current day because, as moment Default section states: You can create a moment object

Custom calendar with bootstrap and momentjs

坚强是说给别人听的谎言 提交于 2020-01-07 03:22:12
问题 I need to create custom calendar, i don't ask for complete code solution here, but i would like only if someone could give me some guidance how i should approach to this, and how to properly do it. I will have list of users and every user have few events with start and end date and i need to show it in calendar like this. Bellow you can see my user object with list of events and i'm not sure how object like that i can show in my custom calendar. I know there are lots of calendar plugins but i