0

it shows this result 1296673200000. i need that in this format m/d/y.how can i do that?

function calDate() {

var date1 = new Date(document.getElementById('date_field1').value);


document.getElementById("date_field2").value = date1.setDate(date1.getDate()+5);
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Airshow
0

Soomro_moon,

A Date object can made in the following ways:

var d = new Date();//Now
var d = new Date(milliseconds);//milliseconds since 1st Jan 1970
var d = new Date(dateString);//eg. ("November 23, 1995 10:30:00")
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);

So, assuming that the value in date_field1 is appropriate:

function calDate() {
	var val = document.getElementById('date_field1').value;
	val += (5 * 24 * 3600 * 1000);//eg, 5 days in milliseconds
	var date1 = new Date(val);
	document.getElementById("date_field2").value = [date1.getMonth()+1,date1.getDate(),date1.getFullYear()].join("/");
	
	//try also 
	//document.getElementById("date_field2").value = date1;
	//document.getElementById("date_field2").value = date1.toDateString();
	//document.getElementById("date_field2").value = date1.toLocaleString();
	//document.getElementById("date_field2").value = date1.toLocaleDateString();
}

The Date objet has many methods:

Airshow

Edited by Airshow: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.