Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Get data and time in javascript

var date_time = new Date().toLocaleString();
console.log(date_time);
Comment

how to use current data in javascript

var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
Comment

how to get the current date and time in javascript

// Getting date and time with javascript 
// example: 1/11/2021 1:34:29

var currentdate = new Date();
var datetime = currentdate.getDay() + "/" + currentdate.getMonth() 
+ "/" + currentdate.getFullYear() + " " 
+ currentdate.getHours() + ":" 
+ currentdate.getMinutes() + ":" + currentdate.getSeconds();

Comment

get current data and time in javascript

To get time and date you should use

    new Date().toLocaleString(); >> "09/08/2014, 2:35:56 AM"

To get only the date you should use

    new Date().toLocaleDateString(); >> "09/08/2014"

To get only the time you should use

    new Date().toLocaleTimeString(); >> "2:35:56 AM"
Comment

javascript current date time

var today = new Date().toLocaleDateString(undefined, {
    day: '2-digit',
    month: '2-digit',
    year: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit'
})
Comment

javascript current date time

function getDateTime() {
        var now     = new Date(); 
        var year    = now.getFullYear();
        var month   = now.getMonth()+1; 
        var day     = now.getDate();
        var hour    = now.getHours();
        var minute  = now.getMinutes();
        var second  = now.getSeconds(); 
        if(month.toString().length == 1) {
             month = '0'+month;
        }
        if(day.toString().length == 1) {
             day = '0'+day;
        }   
        if(hour.toString().length == 1) {
             hour = '0'+hour;
        }
        if(minute.toString().length == 1) {
             minute = '0'+minute;
        }
        if(second.toString().length == 1) {
             second = '0'+second;
        }   
        var dateTime = year+'/'+month+'/'+day+' '+hour+':'+minute+':'+second;   
         return dateTime;
    }

    // example usage: realtime clock
    setInterval(function(){
        currentTime = getDateTime();
        document.getElementById("digital-clock").innerHTML = currentTime;
    }, 1000);
Comment

Getting current date and time in JavaScript

var currentdate = new Date(); 
var datetime = "Last Sync: " + currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/" 
                + currentdate.getFullYear() + " @ "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":" 
                + currentdate.getSeconds();
Comment

PREVIOUS NEXT
Code Example
Javascript :: last item in object javascript 
Javascript :: javascipt get last element of array 
Javascript :: browser javascript update url without changing history 
Javascript :: compare dates in js 
Javascript :: image onclick function react 
Javascript :: first digit javascript 
Javascript :: vuejs scrollBehavior 
Javascript :: naming branches git 
Javascript :: last element in array javascript 
Javascript :: generate a sequence numbers between a range javascript 
Javascript :: add css in javascript 
Javascript :: react native get navigation bar height 
Javascript :: regular expression to find a string between two characters 
Javascript :: firebase timestamp 
Javascript :: js every x seconds 
Javascript :: copy to clipboard react native 
Javascript :: javascript create element in a new line 
Javascript :: angular maxlength directive input type number 
Javascript :: add border to view react native 
Javascript :: string remove accents 
Javascript :: how to make stairs in javascript 
Javascript :: Javascript convert html entity to string 
Javascript :: useLocation in jest 
Javascript :: add variable numerically in javascript 
Javascript :: dayjs timezone 
Javascript :: can we find lenght of an object 
Javascript :: javascript parsefloat() method 
Javascript :: how to iterate object inside object in javascript 
Javascript :: route parammap subscribe angular 9 
Javascript :: como saber si una fecha es mayor que otra en javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =