How can we use momentjs for a time format that has a number of day part prefix?
We can use:
moment("19:41:00", "HH:mm:ss");
What is the time format for:
28.19:41:00
Thanks for helping.
let date = this.moment("28.19:41:00", "DD.HH:mm:ss");
console.log(date.format("YYYY/MM/DD HH:mm:ss")); // 2019/12/28 19:41:00
console.log(date.format("HH:mm:ss")); // 19:41:00
Related
I'm using momentJS to format some dates for a chartJS implementation.
In the chart i'm predicting the next 15 minutes worth of data so need to add the next 15 minutess worth of datetimes to my chartLabel variable.
I use the below function to achieve this. The issue is that the formatting for every other datetime seems to reverse the day and month. I have no idea why this is happening, has anyone seen this before?
predictMarketData(){
let lastDate = this.marketData[this.marketData.length-1][0]
lastDate = moment.unix(lastDate).add(1, 'minutes').format('DD/MM h:mm a')
for(var _i = 0; _i < 15; _i++){
this.chartLabels.push(lastDate);
lastDate = moment(lastDate).add(1, 'minutes').format('DD/MM h:mm a');
}
}
It appears to add minutes correctly but the day month formatting appears to reverse every other, screenshot provided.
Any help would be much appreciated!
How can I use momentjs to format a number in seconds like
moment(172800).format('hh[h] mm[min]')
to some like
'48h 00min'
in essential I want to count timer pass in hh:mm:ss with hours going way beyond 24.
You can use moment-duration-format plug-in.
You can create a duration from your seconds and then use format method from moment-duration-format to print duration according your needs.
Here a example:
// Create moment duration
var dur = moment.duration(172800, 's');
// Format duration according your needs
console.log( dur.format('hh[h] mm[min]') );
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-duration-format/1.3.0/moment-duration-format.min.js"></script>
I want to convert the time from the standard 12-hour reading to the 24-hour one in simpleWeather. When I try to do it, it returns the time in the Unix epoch format.
$(function sunset(){
var sunset=
$.simpleWeather({
location:'Dalol,Afar',
woeid:'',
units:'f',
success:function(weather){
var Sunset= moment(weather.sunset, "HH:mm:ss");
html='Sunset: '+Sunset;
$('#sunset').html(html);
}
});
});
I had contacted the developer on how to do convert it using moment.js, but he didn't say much more than that. How can the code be corrected to display the desired format?
You need to first parse and then format the weather.sunset with the right formatting:
var sunset = moment(weather.sunset, ["h:mm A"]).format("HH:mm");
simpleWeather.js returns the sunset as "5:31 pm" so the corresponding moment format to parse this date is h:mm A, where the A captures the pm/am. To format it in the 24-hour notation, format("HH:mm") will do the job.
I want to display the local time from an ISO 8601 string using momentjs.
There is a discrepancy of minutes when I convert an ISO string using different date formats. If I use 'MM/DD/YYYY HH:mm', the minutes is correctly displayed. If I use 'ddd, MMM Do HH:MMa', 11 minutes is added (in my case).
My sample js (babel) code:
let today = moment('11/09/2016 00:00', 'MM/DD/YYYY HH:mm').toISOString();
//today = 2016-11-09T08:00:00.000Z
let formatted = moment(today, moment.ISO_8601).format('MM/DD/YYYY HH:mm');
//formatted = 11/09/2016 00:00
let formatted2 = moment(today, moment.ISO_8601).format('ddd, MMM Do HH:MMa');
//formatted2 = Wed, Nov 9th 00:11am
I would prefer using the second format. Can someone explain why there is a discrepancy?
Please see this fiddle: https://jsfiddle.net/anudhagat/8fgtjbc7/3/
I caught my silly mistake. I have capitalized the minutes in the second format, using MM makes it display months instead of minutes.
Normally we can get this("2014-04-24 04:50:10 PM") type of date and time from dateField.I need 24 hour date format like this "2014-04-24 16:50:10" . Is this possible ?
You need to use dateformatter
<mx:DateFormatter id="dateFormatter" formatString="YYYY-MM-DD HH:NN:SS"/>
An example is at the very end here