Jquery Countup show only hour and minutes - javascript

I'm using the following Jquery countup script. I'm trying to show only hours and minutes but I can't figure out how to do that. And I'm trying to show the hours and minutes with 2 digits with leading zeros.
Could somebody explain to me how I could achieve this?

This is the snippet I found in above lib:
$(document).ready(function(){
$('#jq_count_up').countUp({'lang':'en', 'format':'full', 'sinceDate': '22/07/2008-00::00'});
});
Now in here, change the value of format. You should follow this lib docs to find out matching format.
Just happened to look into this js file. They have clearly shown the example for this as well...
//example: $.countUp({ 'sinceDate':'01/01/2011', 'lang':'en', 'format':'day' });
//date format: dd/mm/yyyy-hh:mm:ss
//available langs: english (en), turkish (tr), deutsch (de), spanish (es)
//format options: full, day, seconds

Related

MomentJS is sometimes adding the wrong amount of hours

So what i'm simply trying to achieve a feature where i add X.X amount of hours to a 24h time. The issue is for the time 00:00, an incorrect amount of hours is added
The code i wrote works for the most part. It works for every possible time except 0:00.
If i have 01:30 and i add 1h it gives me 02:30. If I have 02:30 and i add 1.5h it gives me 04:00.
So heres this issue. When i have 00:00 and i add 1h i get 01:06...seems to make no sense and i was hoping someone with more momentJS experience might have some thoughts or ideas on the matter. Heres the code
If i have 00:00 and have 3.5 i get 03:06. This all only seems to happen when i start with 00:00. Kind of driving me crazy
console.log(timesheetRows[i][p]); //prints 0:00
console.log(Number(hours)); // prints 1
timesheetRows[i][p] = moment.utc(timesheetRows[i][p], 'hh:mm').add(Number(hours), 'hours').format('HH:MM');
You're using the wrong formats, hh stands for 12 hours and MM stands for two digits month number.
Use something like this:
moment.utc(timesheetRows[i][p], 'HH:mm').add(Number(hours), 'hours').format('HH:mm');

JavaScript + Format duration with Moment.js

I have some JavaScript running in Node. This code dynamically gets a number of seconds. For the sake of this example, I'll choose 180 to represent 3 minutes. I'm trying to format the number of seconds like "3:00" using Moment.js. I'm trying to format the number of seconds using the Moment duration and Moment duration format plugin. My code looks like this:
var duration = 180;
var text = moment.duration(duration, 'seconds').format('mm:ss');
console.log(text);
When I run this, I see text is printed as 00. It's not formatted as I'd expect and I do not understand why. Can someone please explain to me what I'm doing wrong?
Thank you!

Number of hours to HH:MM with Moment.js (or without)

I have very simple problem, but couldn't find good simple DRY solution. I want to convert number of hours to HH:MM format. My try with Moment.js is:
var hours = 10.5
var hour_string = moment(hours*3600*1000).format('HH:MM')
But unfortunately I get:
"11:01"
and have no idea why. Of course my wanted result is "10:30".
I'd like just do it in the easiest way, similar as I can do in Rails:
Time.at(hours*3600).utc.strftime("%H:%M")
Any ideas?
Okay, I found the reason. "MM" means months, not minutes, which are "mm". And the hour shift was caused by timezones, which we can omit using the utc function. The final solution is:
moment.utc(hours*3600*1000).format('HH:mm')

Format date in JS using Moment.js

There is the following code:
console.log(order.start_time);
console.log(moment(order.start_time).format("HH:MM"));
I just want to get hour and minute from date using moment and display it. Output:
2014-06-30T09:00:00.000Z
13:06
But I don't understand why my date is formatted incorrectly. Thanks in advance.
Please note that there is a difference between MM and mm. The first formatting option is used for months, while the second is for days.
More information here: http://momentjs.com/docs/#/parsing/string-format/
From the doc here:
http://momentjs.com/docs/#/displaying/format/
You should use HH:mm. Then your time will have right format.
Further information, the time might be incorrectly as you expected because timezone. Momentjs auto display time in your system timezone.
Update:
To display time in specified Timezone, use "zone" method:
console.log(moment(order.start_time).zone('+00').format("HH:mm"));

jQuery masked input - format date as m/d/yyyy or m/dd/yyyy or mm/dd/yyyy or mm/d/yyyy

I want to use the jQuery masked input plugin found here http://digitalbush.com/projects/masked-input-plugin/ to format the date.
I am pulling data from a database to populate the date field when the page loads. The user will then be able to change the date if it is incorrect.
I want people to be able to enter just one number for the month and day instead of having to enter a 0 before a single-digit number. I want them to be able to type 6/13/2010 instead of 06/13/2010. The data from the database might not have 0's in front, though.
I know that anything listed after a ? is optional, but I want characters at the beginning or middle to be optional.
Thanks!
I had a similar requirement recently, and the only thing I could find that didn't require me to do a lot of work on tweaking the plugin was to use this modified date masking plugin that is based on the one you mentioned. It seems to be doing the job so far.
If you want to test it out, head to this page.
The basic implementation we've used with this modified date masker is as follows:
$('#yourInputBoxHere').mask("99/99/9999", {placeholder: 'MM/DD/YYYY' });
I haven't tried it with single digits for dates, but if I were to do it, I'd just change the above expression to this:
$('#yourInputBoxHere').mask("9/9/9999", {placeholder: 'M/D/YYYY' });
I hope this helps.
The short answer is:
It's not possible without tweaking the plugin.
But, your users will thank you a lot if you use the jquery ui datepicker.
It's usage is as simple as:
$("#texbox1").datepicker();
It will show a nice calendar when the inputbox recieves focus.
Hope this helps. Cheers
I am not sure if this addresses your problem but I found this on https://github.com/RobinHerbots/jquery.inputmask:
$('#yourInputBoxHere').datepicker().inputmask("date", { placeholder: "mm/dd/yyyy", yearrange: { minyear: 1700 } });
This will fill in a '0' at the month beginning if you start with a number greater than '1' and for the day if the number is greater than 3, '0' is automatically placed in front.
The yearrange can also specify maxyear, if you need that criteria.
You can leave out the .datepicker() if you don't want the jquery calendar.
Hope this helps!

Categories

Resources