我用js 从后台获取了时间戳 用以下这个函数 将时间戳转化为日期
function getLocalTime(nS)
{
return new Date(parseInt(nS) * 1000).toLocaleString().substr(0,9);
};
在电脑上看是好的 得到的日期格式为 2015/9/1
但是在苹果手机中显示的是 中文 2015年9月1
在安卓手机中得到的是英文 tue sep 0
请问大家怎么解决这个问题 我想要在不同的机器上获得 统一的格式的日期。
谢谢。
最后这么写解决了:
function getLocalTime(nS) {
var ss = new Date(parseInt(nS) * 1000 ) ;
return ss.getFullYear()+'/'+(ss.getMonth()+1)+"/"+ss.getDate();
};
这个由浏览器控制,你想统一就自己写toLocaleString函数来实现格式统一
Date.prototype.toLocaleString = function () {
return this.getFullYear()+'-'+(this.getMonth()+1)+'-'+this.getDate()+' '+this.getHours()+':'+this.getMinutes()+':'+this.getSeconds()
}
var date = new Date();
alert(date.toLocaleString())
toLocaleString()
本来就是 当地日期格式
你可以用
Date.Format("yyyyMMdd")
之类的统一
Java:
SimpleDateFormat time=new SimpleDateFormat("yyyyMMdd");
System.out.println(time.format(nowTime));