2016-10-13 00:16:48 点击量:84 标签: 收藏本文
[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;
- }
- }
我们是一家提供综合软件外包与弱电工程服务的技术公司。
业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。
公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室