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);
    		}
    	}
    
    }
    
  • 相关阅读:
    二分搜索
    Shell 字符串处理、获取文件名和后缀名
    sqlldr使用说明
    Linux cached过高问题
    算法时间复杂度
    #if,#ifdef,#ifndef的区别
    memcpy momove strcmp源码实现
    怎么解决/bin/sh: arm-linux-gcc: not found make
    性能文章
    linux
  • 原文地址:https://www.cnblogs.com/602147629/p/1979629.html
Copyright © 2011-2022 走看看