Skip to main content

JS Date Time functions - How to get Current Day, Month, Year and time using Javascript?

How to get Current Day, Month, Year and time using Javascript?

There are several Date and time functions in JS to retrive current Date, Day name, Month name, year and Time

Javascript has a special class called Date, this Date class is initiated by creating a Date object and using several functions in the Date class we can access segments of Current Date and time

How to create a Date object:

// declare date object
var today = new Date();

Date and Time function in JS:

//get current day
today.getUTCDay()

// current month
today.getUTCMonth()

// get current year
today.getFullYear()

//get Hour of the day
today.getHours();

//get minute of the day
today.getMinutes();

//get second
today.getSeconds();

Here is a simple illustration of above mentioned functions


<script>
function getDateTime()
{


var daysOfWeek = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

var months=new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

var today = new Date();

var hour = today.getHours();
var minute = today.getMinutes();
var second = today.getSeconds();

var date = "<b>today:</b> " + daysOfWeek[today.getUTCDay()] + ", " + months[today.getUTCMonth()] + " " + today.getUTCDate() + " "+ today.getFullYear() + " "+ hour+ " : "+ minute + " : "+ second;

return(date);

}

alert( getDateTime() );

</script>



Reference: W3Schools ( http://www.w3schools.com/jsref/jsref_obj_date.asp )

Comments

Popular posts from this blog

Intex Aqua 5.5 VR Plus genuine Review - Dont Buy Intex Aqua 5.5 VR Plus - Board complaint and low battery backup issues

Intex Aqua 5.5 VR Plus  Review - Dont Buy Intex Aqua 5.5 VR + - Board complaint and low battery backup issues I bought an Intex Aqua 5.5 VR Plus on April 23, 2018, With in a week it started to show Battery backup issues. Even if it is charged full, it will completely drain out with in 12 or 13 hours. During this time No internet was used, only 2 or 3 calls were done. Some times there was issues with net connection also.

Deep-sea Anglerfish Black Seadevil Scary looking creature Video

Deep-sea Anglerfish are the strange and elusive creature that are very rarely observed in their natural habitat. Fewer than half a dozen have ever been captured on film or video by deep-diving research vehicles.They are mostly  found in tropical to temperate waters of the Indian,Pacific and Atlantic Oceans.

How to use WiFi adapter on Ubuntu 16.04 desktop PC - Realtek RTL8188EUS 802.11n Wireless USB Network Adapter Driver installation

Installation of Realtek RTL8188EUS 802.11n Wireless USB Network Adapter on Desktop PC having Ubuntu 16.04 OS My PC is running in Ubuntu 16.04 OS, recently I thought of using a dongle wife adapter to access our home's Wifi network. For this I used Realtek RTL8188EUS 802.11n Wireless USB Network Adapter ( Model No: OT-WUA950NM ) This small device cost around Rupees 250/- to Rs 300/- in India. I did the following steps for installation of this Realtek Nano Wifi Adapter: Plug Realtek RTL8188EUS 802.11n Wireless USB Network Adapter to your PC's USB port, Take the terminal application and run the command "lsusb" to list the plugged in usb devices: Myhome:~$ lsusb Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 003: ID 0bda:8179 Realtek Semiconductor Corp. R...


Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »
Member
Search This Blog