• 操作规范时间工具类


    var D:Date = StringToDate.parse("2011-03-04 15:22:21");
    var d:Date = StringToDate.parse("2011-03-09 13:22:21");
    
    showTimerTxt(d,D);
    
    function showTimerTxt(d:Date,D:Date):void
    {
    	var time:Number=(d.getTime()-D.getTime())/1000/60/60/24;
    	trace(d.getTime()-D.getTime());
    	if (time >= 1)
    	{
    		_timerTxt.text = "在" + Math.floor(time) + "天前";
    	}
    	else
    	{
    		var temp:Number = time * 24;
    		if (temp >= 1)
    		{
    			_timerTxt.text = "在" + Math.floor(temp) + "小时前";
    		}
    		else
    		{
    			_timerTxt.text = "在" + Math.floor(temp * 60) + "分钟前";
    		}
    
    	}
    }
    
    package 
    {
    	public class StringToDate
    	{
    
    		public function StringToDate()
    		{
    
    		}
    		public static function parse(dateString:String):Date
    		{
    			if (dateString == null)
    			{
    				return null;
    			}
    			if (dateString.indexOf("0000-00-00") != -1)
    			{
    				return null;
    			}
    			dateString = dateString.split("-").join("/");
    			return new Date(Date.parse( dateString ));
    		}
    		public static function transform(time:uint, stringMode:Boolean=false):String
    		{
    			if (stringMode)
    			{
    				var hours:uint = getHours(time);
    				var minutes:uint = getMinutes(time);
    				var seconds:uint = getSecond(time);
    				return (hours < 10?"0" + hours:hours) + ":" + (minutes < 10?"0" + minutes:minutes) + ":" + (seconds < 10?"0" + seconds:seconds);
    			}
    			return getHours(time)+"h"+getMinutes(time)+"m"+getSecond(time)+"s";
    		}
    		public static function getHours(needSecond:uint):uint
    		{
    			return uint(needSecond / (60 * 60));
    		}
    
    		public static function getMinutes(needSecond:uint):uint
    		{
    			return uint(needSecond % (60 * 60) / 60 );
    		}
    
    		public static function getSecond(needSecond:uint):uint
    		{
    			return uint(needSecond % (60 * 60) % 60);
    		}
    	}
    
    }
    
  • 相关阅读:
    winform中文本框添加拖拽功能
    jQuery返回顶部代码
    判断IP地址是否在指定范围内的方法
    jQuery提示通知插件jBox
    Windows 8.1 SecureBoot未正确配置的解决方法
    操作系统下载
    js中(function(){…})()立即执行函数写法理解
    。net MVC 序列化 反序列化
    js点击button按钮跳转到页面代码
    单例模式
  • 原文地址:https://www.cnblogs.com/602147629/p/1979629.html
Copyright © 2020-2023  润新知