[as3]AS3时间时间戳
[as3]AS3时间时间戳 根据unix时间戳返回一个相对当前时间的格式,如:3天前,24秒前等等
[as3]AS3时间时间戳
根据unix时间戳返回一个相对当前时间的格式,如:3天前,24秒前等等
- //###############################
- //Usage:
- var myRelativeTime:String = timestampToRelative("Sun Oct 24 20:07:33 +0000 2010");
- //returns a string
- //###############################
- function timestampToRelative(timestamp:String):String {
- //--Parse the timestamp as a Date object--\\
- var pastDate:Date = new Date(timestamp);
- //--Get the current data in the same format--\\
- var currentDate:Date = new Date();
- //--seconds inbetween the current date and the past date--\\
- var secondDiff:Number = (currentDate.getTime() - pastDate.getTime())/1000;
- //--Return the relative equavalent time--\\
- switch (true) {
- case secondDiff < 60 :
- return int(secondDiff) + ' seconds ago';
- break;
- case secondDiff < 120 :
- return 'About a minute ago';
- break;
- case secondDiff < 3600 :
- return int(secondDiff / 60) + ' minutes ago';
- break;
- case secondDiff < 7200 :
- return 'About an hour ago';
- break;
- case secondDiff < 86400 :
- return 'About ' + int(secondDiff / 3600) + ' hours ago';
- break;
- case secondDiff < 172800 :
- return 'Yesterday';
- break;
- default :
- return int(secondDiff / 86400) + ' days ago';
- break;
- }
- }
热门文章推荐
- [JS]window.location获取url各项参数详解
- [JS]jQuery,javascript获得网页的高度和宽度
- [JS]视频弹窗视频弹出层videoLightBox(含三种播放器的用法)
- [JS]JS提交中文encodeURI两次转码
- [JS]js版方面encodeURI转码和decodeURI解码的用法实例
- [JS]js取当前机子的时间戳实例
- [JS]AES加密(基于crypto-js)PHP后端解密
- [JS]data:image/png;base64写法的用途及说明
请稍候...