zoukankan      html  css  js  c++  java
  • 操作规范时间工具类

    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);
    		}
    	}
    
    }
    
  • 相关阅读:
    风火轮 –动画效果:擦除、形状、轮子、随机线条、翻转远近、缩放、旋转、弹跳效果
    风火轮 –动画效果:浮入与劈裂
    风火轮 – 飞入动画效果
    风火轮 1
    CB XE6初体验
    在CB2010中调用ffmpeg(5)
    在CB2010中调用ffmpeg(4)
    在CB2010中调用ffmpeg(3)
    在CB2010中调用ffmpeg(2)
    0-99累加
  • 原文地址:https://www.cnblogs.com/602147629/p/1979629.html
Copyright © 2011-2022 走看看