回到顶部

as3 时间格式工具

时间:6年前   作者:CnctSoft   浏览:243   [站内原创,转载请注明出处]

标签: AS3  

public class DateUtil
	{
		public static function getUnixTimestamp():int{
			return new Date().time/1000;
		}
		
		/**
		 * 将日期格式化成YYYY-MM-DD格式 
		 * @param date Date
		 * @return str String
		 * 
		 */		
		public static function formatDateYYYYMMDD(date:Date):String
		{
			var fullYear:String = date.fullYear.toString();
			var month:String = date.month+1>9 ? (date.month+1).toString() : "0"+(date.month+1).toString();
			var _date:String = date.date>9 ? date.date.toString() : "0" + date.date.toString();
			return fullYear + "-" + month + "-" + _date;
		}
		
		/**
		 * 将日期格式化成YYYY-MM-DD HH:JJ:SS格式 
		 * @param date
		 * @return 
		 * 
		 */		
		public static function formatDate(date:Date):String
		{
			var fullYear:String = date.fullYear.toString();
			var month:String = date.month+1>9 ? (date.month+1).toString() : "0"+(date.month+1).toString();
			var _date:String = date.date>9 ? date.date.toString() : "0" + date.date.toString();
			var hours:String = date.hours > 9 ? date.hours.toString() : "0" + date.hours.toString();
			var minutes:String = date.minutes>9 ? date.minutes.toString() : "0" + date.minutes.toString();
			var seconds:String = date.seconds > 9 ? date.seconds.toString() : "0" + date.seconds.toString();
			return fullYear + "-" + month + "-" + _date + " " + hours + ":" + minutes + ":" + seconds;
		}
		
		public static function formatDateHHMMSS(date:Date):String
		{
			var hours:String = date.hours > 9 ? date.hours.toString() : "0" + date.hours.toString();
			var minutes:String = date.minutes>9 ? date.minutes.toString() : "0" + date.minutes.toString();
			var seconds:String = date.seconds > 9 ? date.seconds.toString() : "0" + date.seconds.toString();
			return hours + ":" + minutes + ":" + seconds;
		}
		
		public static function formatDateHHMMSS_SSS(date:Date):String
		{
			var hours:String = date.hours > 9 ? date.hours.toString() : "0" + date.hours.toString();
			var minutes:String = date.minutes>9 ? date.minutes.toString() : "0" + date.minutes.toString();
			var seconds:String = date.seconds > 9 ? date.seconds.toString() : "0" + date.seconds.toString();
			var mill:String = date.milliseconds.toString();
			if(date.milliseconds < 10)
				mill = "00" + date.milliseconds;
			else if(date.milliseconds < 100)
				mill = "0" + date.milliseconds;
			return hours + ":" + minutes + ":" + seconds + "." + mill;
		}
		
		public function DateUtil()
		{
		}
	}



内容均为作者独立观点,不代表八零IT人立场,如涉及侵权,请及时告知。

评论努力加载中...
暂无评论
暂无评论

手机扫码阅读

热门相关

加载中...
关于我们   联系我们   申请友链   赞助记录   站点地图
© 2014 - 2017 www.80iter.com All Rights Reserved. 京ICP备14042174号-1
本站遵循 CC BY 4.0 协议,转载请注明出处 。