测试了下as3的日期时间格式化
星期日, 2011-01-23 | Author: Lee | as | 8,067 views
在java中格式化日期很方便,在as3中找不到对应的函数,自己写个吧,也很方便,简单用flex测试了下
如此的日期格式:2011-01-23 00:36:31
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" initialize="init()"> <fx:Declarations> <!--power by I5A6 --> </fx:Declarations> <fx:Script> <![CDATA[ import mx.formatters.DateFormatter; private function init():void{ timeBut.addEventListener(MouseEvent.CLICK,handleClick); } private function handleClick(event:MouseEvent):void{ var date:Date=new Date(); var dateStr:String=getDateString(date); lable.text+=dateStr+"\n"; trace(dateStr); } static public function getDateString(date:Date):String{ var date:Date=new Date(); var year:String=String(date.getFullYear()); var month:String=String((date.getMonth()+1)<10?"0":"")+(date.getMonth()+1); var day:String=String(date.getDate()<10?"0":"")+(date.getDate()); var hours:String=String(date.getHours()<10?"0":"")+date.getHours(); var min:String=String(date.getMinutes()<10?"0":"")+date.getMinutes(); var second:String=String(date.getSeconds()<10?"0":"")+date.getSeconds(); return year+"-"+month+"-"+day+" "+hours+":"+min+":"+second; } ]]> </fx:Script> <s:VGroup width="100%"> <s:Button id="timeBut" label="获取当前时间" /> <s:Label id="lable"/> </s:VGroup> </s:Application> |
文章作者: Lee
本文地址: https://www.pomelolee.com/727.html
除非注明,Pomelo Lee文章均为原创,转载请以链接形式标明本文地址
No comments yet.
Leave a comment
Search
相关文章
热门文章
最新文章
文章分类
- ajax (10)
- algorithm-learn (3)
- Android (6)
- as (3)
- computer (85)
- Database (30)
- disucz (4)
- enterprise (1)
- erlang (2)
- flash (5)
- golang (3)
- html5 (18)
- ios (4)
- JAVA-and-J2EE (186)
- linux (143)
- mac (10)
- movie-music (11)
- pagemaker (36)
- php (50)
- spring-boot (2)
- Synology群晖 (2)
- Uncategorized (6)
- unity (1)
- webgame (15)
- wordpress (33)
- work-other (2)
- 低代码 (1)
- 体味生活 (40)
- 前端 (21)
- 大数据 (8)
- 游戏开发 (9)
- 爱上海 (19)
- 读书 (4)
- 软件 (3)