You can do it like that: var d = new Date(); var month = d. getMonth()+1; var day = d. getDate(); var output = d.
jQuery is a lightweight, "write less, do more", JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.
You may try like this:
new Date($.now());
Also using Javascript you can do like this:
var dt = new Date();
var time = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
document.write(time);
You need to fetch all "numbers" manually
like this:
var currentdate = new Date();
var datetime = "Now: " + currentdate.getDate() + "/"
+ (currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear() + " @ "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":"
+ currentdate.getSeconds();
document.write(datetime);
Convert a Date
object to an string, using one of Date.prototype
's conversion getters, for example:
var d = new Date();
d+''; // "Sun Dec 08 2013 18:55:38 GMT+0100"
d.toDateString(); // "Sun Dec 08 2013"
d.toISOString(); // "2013-12-08T17:55:38.130Z"
d.toLocaleDateString() // "8/12/2013" on my system
d.toLocaleString() // "8/12/2013 18.55.38" on my system
d.toUTCString() // "Sun, 08 Dec 2013 17:55:38 GMT"
Or, if you want it more customized, see the list of Date.prototype
's getter methods.
The native JavaScript implementation is Date.now()
.
Date.now()
and $.now()
return the same value:
Date.now(); // 1421715573651
$.now(); // 1421715573651
new Date(Date.now()) // Mon Jan 19 2015 20:02:55 GMT-0500 (Eastern Standard Time)
new Date($.now()); // Mon Jan 19 2015 20:02:55 GMT-0500 (Eastern Standard Time)
..and if you want the time formatted in hh-mm-ss:
var now = new Date(Date.now());
var formatted = now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
// 20:10:58
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With