VincentLoy/simplyCountdown.js

Date Format Question

oleteacher opened this issue ยท 4 comments

Excellent work, thank you for sharing!

Is there any way to format the date within simplyCountdown so that standard date pickers can be used? Example: I have input form and users pick a date using https://cdnjs.com/libraries/bootstrap-datetimepicker

Since most date / time pickers can use formats like "2018-12-31 23:55:21", is there way to use this format with simplyCountdown?

Thanks!

Hello @oleteacher !
Thanks a lot for your support !

Actually, there is no way to do that directly. You'll have to parse the date given by the Bootstrap Datetimepicker plugin. But it's quite simple, I suppose that the datetimepicker plugin will give you a date object, so you can then get the year, month, day, etc.

Otherwise, if you want to contribute, we can easly improve simplyCountdown plugin to allow users to pass datetime object directly in parameters. The only thing we have to watch out is a priority system like :

  • If date object is given, use it for targetTmpDate
  • else, use other params to build targetTmpDate

Greets!

I had tooled around with the plugin and found no simple way to use with standard date/time pickers. If the opportunity arises in the future, will revisit and try to convert in classroom project:)

Thanks!

Sound great ! Very happy that the plugin can be used in a educational way ! ๐Ÿ˜„ ๐ŸŽ‰

I just remember that in the demo, I'm using the plugin with Date objects...

var d = new Date();

simplyCountdown('.simply-countdown-one', {
    year: d.getFullYear(),
    month: d.getMonth() + 1, // Because January is 0 and December is 11
    day: d.getDate(),
    // etc ...
});

So you can get the date object from the plugin and use it like in the example.