日期格式的动作 [英] Date Formatting in actionscript

查看:125
本文介绍了日期格式的动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:我需要一个日期(字符串数据类型)的用户。现在,我想知道,如果在动作AA功能,将其转换为一个日期格式。现在,我只是解析字符串连接这些碎片重新走到一起。即:

I have the following problem: I take a date (as a string data type) from the user. Now, I want to know if there is a a function in actionscript that will convert it to a date format. Right now, I am just parsing the string and concatenating the pieces back together. Ie:

changeDateString = date.getFullYear().toString() + '/' + (date.getMonth()+1).toString() + '/' + date.getDate();

不过数月月一样,它会返回5,而不是05。我也有类似的问题,为天,如9或7。有什么库,这将帮我这个忙? (就目前而言,我可以继续手动串联在前面的0,而这似乎是件麻烦的事。)

But for months like May, it will return "5" and not "05". I have similar problems for days like "9" or "7." Is there something in the library that will do this for me? (For the moment, I can go ahead and manually concatenate the "0" in front, but this seems like a hassle to do.)

我知道这是一个简单的问题,但我是新手。

I know this is a simple question, but I a novice.

感谢。

推荐答案

使用的日期格式为:

<一个href="http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/mx/formatters/DateFormatter.html">http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/mx/formatters/DateFormatter.html

您配置您的格式使用的格式的基础上列出的类型,并用它来输出你的日期。

You configure your formatter to use the format based on the types listed and use it to output your date.

var formatter:DateFormatter = new DateFormatter();
formatter.formatString = "m/d/Y";
var example:Date = new Date(2010, 0, 5, 10, 25);
trace(formatter.format(example));  // Displays: 01/05/2010

只需使用模式字母/说明电网中的文档,找到正确的格式为您的需求。

Just use the Pattern Letter/Description grid in the docs to find the right format for your needs.

这篇关于日期格式的动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆