<script type="text/javascript">
/*
*演示JS中的日期
*/
var date = new Date();
document.write(date.toLocaleString()+"<br/>");//日期和时间
document.write(date.toLocaleDateString()+"<br/>");//只有日期
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDate();
var week = getWeek(date.getDay());
document.write(year+"-"+month+"-"+day+"-"+week+"<br/>");
//获取星期的函数
function getWeek(num){
var weeks = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
return weeks[num];
}
//日期对象和毫秒值之间的转换
var date2 = new Date();
//获取毫秒值。日期对象-->毫秒值
var time = date2.getTime();
document.write("time:"+time+"<br/>");
//将毫秒值转成日期对象
var date3 = new Date(time);
document.write("date:"+date3+"<br/>");
//将日期对象和字符串之间进行转换
//日期对象转换成字符串。toLocateString
//将字符串转成日期对象。具备指定格式的日期字符串-->毫秒值-->日期对象
var str_date = "9/28/2017";
var time2 = Date.parse(str_date);
var date3 = new Date(time2);
document.write(date3.toLocaleDateString());
</script>