日期到字符串< - >字符串到日期 [英] Date to String <-> String to Date
问题描述
所以在Flex我这样做:
public static function dateToString(cDate:Date):String {
返回cDate.date.toString()+。+
cDate.month.toString()+。+
cDate.fullYear.toString()++
cDate .hours.toString()+:+
cDate.minutes.toString()+:+
cDate.seconds.toString();
}
但我得到的结果如下:
13.7.2010 0:0:15
如何用填充0填充日,月,小时,分,秒? p>
而且,我从String返回到日期:
DateField。 stringToDate(myTextInput.text,DD.MM.YYYY HH:MM:SS);
这是正确的吗?我想有一个日期,我将通过BlazeDS转移到J2EE后端,但我只在数据库中看到一个空值。所以有什么问题...
最好的问候。
您是否看过 DateFormatter 课程?
示例:
import mx.formatters.DateFormatter;
private var dateFormatter:DateFormatter;
私有函数init():void
{
dateFormatter = new DateFormatter();
dateFormatter.formatString ='DD.MM.YYYY HH:NN:SS'
}
public function dateToString(d:Date):String
{
return dateFormatter.format(d);
}
public function stringToDate(s:String):Date
{
return dateFormatter.parseDateString(s);
}
看起来有人在撰写Flex 3.2的那一天睡着了,因为 DateFormatter :: parseDateString
是一个受保护的函数。看起来他们固定了3.5。
I get a Date of my database and I need to show it as a String. So in Flex I do this:
public static function dateToString(cDate:Date):String {
return cDate.date.toString()+"."+
cDate.month.toString()+"."+
cDate.fullYear.toString()+" "+
cDate.hours.toString()+":"+
cDate.minutes.toString()+":"+
cDate.seconds.toString();
}
But I get for example the result:
13.7.2010 0:0:15
How can I fill the day, month, hours, minutes, seconds with padded 0?
And, I go back from String to Date with:
DateField.stringToDate(myTextInput.text, "DD.MM.YYYY HH:MM:SS");
Is this correct? I want to have a Date which I will transfer via BlazeDS to a J2EE Backend, but I only see in the database then a null value. So something is going wrong...
Best Regards.
Have you seen the DateFormatter class?
Example:
import mx.formatters.DateFormatter;
private var dateFormatter:DateFormatter;
private function init():void
{
dateFormatter = new DateFormatter();
dateFormatter.formatString = 'DD.MM.YYYY HH:NN:SS'
}
public function dateToString(d:Date):String
{
return dateFormatter.format(d);
}
public function stringToDate(s:String):Date
{
return dateFormatter.parseDateString(s);
}
It looks like somebody was asleep the day the wrote Flex 3.2, because DateFormatter::parseDateString
is a protected function. It looks like they fixed that by 3.5.
这篇关于日期到字符串< - >字符串到日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!