Answers for "how to get time and date in js"

19

javascript get current time

var today = new Date();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
Posted by: Guest on March-30-2020
4

javascript get date without time

function WithoutTime(dateTime) {
    var date = new Date(dateTime.getTime());
    date.setHours(0, 0, 0, 0);
    return date;
}
Posted by: Guest on July-10-2020
7

javascript date get current date

var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
//var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date+' '+time;
The dateTime variable contains result as:

2018-8-3 //11:12:40
Posted by: Guest on May-19-2020
3

get time from date javascript

const handleTime = (dataD) => {
    let data= new Date(dataD)
    let hrs = data.getHours()
    let mins = data.getMinutes()
    if(hrs<=9)
       hrs = '0' + hrs
    if(mins<10)
      mins = '0' + mins
    const postTime= hrs + ':' + mins
    return postTime
  }
Posted by: Guest on August-08-2020
1

get time in javascript

//HTML
<a onclick="timeNow(test1)" href="#">SET TIME</a>
//Javascript
function timeNow(i) {
  i.value = new Date()
}
Posted by: Guest on August-06-2020

Code answers related to "how to get time and date in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language