blog post

Get current local Date Time in JQuery.

JavaScript code get the current date in the format dd/mm/yyyy. The month is formatted to prefix with a zero (ie “04”) for single month figures. Also, here is how you can get a future date using jQuery. DateFormatter(new Date(),0); its return Today date: dd/mm/yyyy Ex: 12/03/2016 DateFormatter(new Date(),1); its return Today date: dd/mm/yyyy Ex: 2016-03-12
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<head>
<title>Jquery Date Formate : Theoneblogs.com</title>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="keywords">
<meta name="author" content="Atul Shukla">

<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script>
$(document).ready(function(){

var todayDate=DateFormatter(new Date(),0);
var yesterdayDate=GetYesterdayDate(new Date(),0);
var tomorrowDate=GetTomorrowDate(new Date(),0);

$("#yesterday").html(yesterdayDate);
$("#today").html(todayDate);
$("#tomorrow").html(tomorrowDate);


});

function DateFormatter(dateObject,dateformates) {
    var d = new Date(dateObject);
    var day = d.getDate();
    var month = d.getMonth() + 1;
    var year = d.getFullYear();
    if (day < 10) {
        day = "0" + day;
    }
    if (month < 10) {
        month = "0" + month;
    }
    var date='';
    
    if(dateformates==1)
    	{
    	date= year + "-" + month + "-" +day ;
    	}else
    		{
    		date= day + "/" + month + "/" + year;	
    		}
    

    return date;
}; 





function GetYesterdayDate(dt,dateformates) {
    var date = new Date(dt);
    date.setDate(date.getDate()-1);
    
    var day = date.getDate();
    var month = (date.getMonth()+1);
    var year = date.getFullYear();
    if (day < 10) {
        day = "0" + day;
    }
    if (month < 10) {
        month = "0" + month;
    }
    if(dateformates==1)
	{
	date= year + "-" + month + "-" +day ;
	}else
		{
		date= day + "/" + month + "/" + year;	
		}
    return date;
}





function GetTomorrowDate(dt,dateformates) {
	 var date = new Date(dt);
	    date.setDate(date.getDate()+1);
	    
	    var day = date.getDate();
	    var month = (date.getMonth()+1);
	    var year = date.getFullYear();
	    if (day < 10) {
	        day = "0" + day;
	    }
	    if (month < 10) {
	        month = "0" + month;
	    }
	    if(dateformates==1)
   	{
   	date= year + "-" + month + "-" +day ;
   	}else
   		{
   		date= day + "/" + month + "/" + year;	
   		}
	    return date; 
}



</script>


<body style="text-align:center">

<h2>Date Formate:</h2>

<div><b>Today Date: </b><span id="today"></span></div><br/>
<div><b>Tomorrow Date: </b><span id="tomorrow"></span></div><br/>
<div><b>Yesterday Date: </b><span id="yesterday"></span></div><br/>


</body>

<html>

</html>

jQuery Get Todays Date
  • Share This Story


Pleas give your valuable comments to improve the contents.

about author

Atul kumar shukla


I'm Atul Kumar Shukla, working as a web developer.
Welcome to my Blog. This is my personal blog where i post my own questions and answers , articles about ASP.Net., SQL Server, HTML, CSS, Jquery and many more..

Visit Profile

Leave a comment

Name
E-mail
Url
Message

Get More Stuff
Subscribing to the TheOneblogs newsletter and get intersting stuff and updates to your email inbox.
Your Email

 

Style Switcher

Change Color

×! We use cookies to improve your user experience. More information