•  0
    JavaScript

    Get current date using JavaScript

      Admin     2526        0        Report content

    Function to return the current date

    
    function getCurrentDate()
    {
    var d = new Date();
    var currentTime = d.toLocaleTimeString();
    var currentMin = d.getMinutes();
    var currentHour = d.getHours();
    var today = d.getDay();
    var todayDate = d.getDate();
    var currentMonth = d.getMonth();
    var currentYear = d.getFullYear();
    
    if(today == 0){ today = 'Sunday';}
    else if(today == 1){ today = 'Monday';}
    else if(today == 2){ today = 'Tuesday';}
    else if(today == 3){ today = 'Wednesday';}
    else if(today == 4){ today = 'Thursday';}
    else if(today == 5){ today = 'Friday';}
    else if(today == 6){ today = 'Saturday';}
    
    if(currentMonth == 0){ currentMonth = 'January'}
    else if(currentMonth == 1){ currentMonth = 'February'}
    else if(currentMonth == 2){ currentMonth = 'March'}
    else if(currentMonth == 3){ currentMonth = 'April'}
    else if(currentMonth == 4){ currentMonth = 'May'}
    else if(currentMonth == 5){ currentMonth = 'Jun'}
    else if(currentMonth == 6){ currentMonth = 'July'}
    else if(currentMonth == 7){ currentMonth = 'August'}
    else if(currentMonth == 8){ currentMonth = 'September'}
    else if(currentMonth == 9){ currentMonth = 'October'}
    else if(currentMonth == 10){ currentMonth = 'November'}
    else if(currentMonth == 11){ currentMonth = 'December'}
    
    return today+', '+todayDate+' '+currentMonth+' '+currentYear+'  '+currentTime;
    }

    How to use :
    var currentDate = getCurrentDate();

     

     


  •  


Leave a Comment

Please Login to insert comment.

 

Facebook Conversations