zoukankan      html  css  js  c++  java
  • 日期时间格式化(Date对象)

    var DAYS: Array = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
    
    var nowTimeData=new Date();
    trace("当前时间:"+nowTimeData);
    
    var nowTimeFormat=getDateString(new Date());
    trace("当前时间:"+nowTimeFormat)
    
    function getDateString(date: Date): String {
    	var dYear: String = String(date.getFullYear());
    
    	var dMouth: String = String((date.getMonth() + 1 < 10) ? "0" : "") + (date.getMonth() + 1);
    
    	var dDate: String = String(date.getDate() < 10 ? "0" : "") + date.getDate();
    
    	var ret: String = "";
    
    	ret += dYear + "/" + dMouth + "/" + dDate + " ";
    
    	ret += DAYS[date.getDay()] + " ";
    
    	ret += ((date.getHours() < 10) ? "0" : "") + date.getHours() + ":";
    
    	ret += ((date.getMinutes() < 10) ? "0" : "") + date.getMinutes() + ":";
    
    	ret += ((date.getSeconds() < 10) ? "0" : "") + date.getSeconds();
    
    	// 想要获取秒的话,date.getSeconds() ,语句同小时、分
    
    	return ret;
    }
    

      

    输出:

    当前时间:Mon Mar 15 10:12:05 GMT+0800 2021
    当前时间:2021/03/15 周一 10:12:05

    参考:https://blog.csdn.net/ch_kexin/article/details/84467719

  • 相关阅读:
    基于Twisted的简单聊天室
    小学题的python实现
    初识Go(8)
    初识Go(7)
    初识Go(6)
    初识Go(5)
    初识Go(4)
    初识Go(3)
    初识Go(2)
    初识Go(1)
  • 原文地址:https://www.cnblogs.com/dt1991/p/14536014.html
Copyright © 2011-2022 走看看