Advertisemen
There might be a time where you don't want to or can't use php to display date and time in your application but you can use javascript. So, let's take a look how to display date and time using javascript.
There are four ways to instantiate the date function in javascript.
var d = new Date();
var d = new Date(milliseconds);
var d = new Date(dateString);
var d =
new Date(year, month, day, hours, minutes, seconds, milliseconds);
var d = new Date(milliseconds);
var d = new Date(dateString);
var d =
new Date(year, month, day, hours, minutes, seconds, milliseconds);
Let's take a look at the examples of these.
var d = new Date();
This is going to return the current date in the following format.
ex :
Thu Jul 07 2016 16:17:44 GMT+1000 (AEST)
This is going to return the current date in the following format.
ex :
Thu Jul 07 2016 16:17:44 GMT+1000 (AEST)
var d = new Date(milliseconds);
This is going to convert the milliseconds into the default date time format.
ex :
var d = new Date(35500000) = Thu Jan 01 1970 19:51:40 GMT+1000 (AEST)
This is going to convert the milliseconds into the default date time format.
ex :
var d = new Date(35500000) = Thu Jan 01 1970 19:51:40 GMT+1000 (AEST)
var d = new Date(dateString);
ex :
var d = new Date("December 1, 2016 10:00:00")= Thu Dec 01 2016 10:00:00 GMT+1100 (AEDT)
ex :
var d = new Date("December 1, 2016 10:00:00")= Thu Dec 01 2016 10:00:00 GMT+1100 (AEDT)
var d =
new Date(year, month, day, hours, minutes, seconds, milliseconds);
ex:
var d =
new Date(2016,1,30,12,16,28,0) = Tue Mar 01 2016 12:16:28 GMT+1100 (AEDT)
new Date(year, month, day, hours, minutes, seconds, milliseconds);
ex:
var d =
new Date(2016,1,30,12,16,28,0) = Tue Mar 01 2016 12:16:28 GMT+1100 (AEDT)
In part 2 of this tutorial, we will learn to get date separately.
Part 2
Advertisemen
Tidak ada komentar:
Posting Komentar