从 Rails 到 Flex 的日期/时间转换问题?

发布于 2024-08-16 19:29:57 字数 204 浏览 2 评论 0原文

我收到以下错误: TypeError:错误#1034:类型强制失败:无法将“2010-01-02 23:28:17 UTC”转换为日期。

我正在使用 WebORB 在 Rails 和 Flex 之间传输数据。来自 Rails 的数据类型为:“ActiveSupport::TimeWithZone”。我正在尝试将其分配给 Flex“日期”数据类型。

我缺少什么?

I am getting the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert "2010-01-02 23:28:17 UTC" to Date.

I am using WebORB to transfer data between Rails and Flex. The data coming from Rails is of type: 'ActiveSupport::TimeWithZone'. I am trying to assign it to a Flex 'Date' data type.

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羁〃客ぐ 2024-08-23 19:29:57

来自文档:http://www.adobe。 com/livedocs/flex/3/langref/Date.html#Date()

如果将字符串传递给 Date 类构造函数,则日期可以采用多种格式,但必须至少包含月、日和年。例如,2005 年 2 月 1 日有效,但 2005 年 2 月无效。下面的列表指出了一些有效的格式:

日月日时:分:秒 GMT 年(例如“Tue Feb 1 00:00:00 GMT-0800 2005”,与 toString() 匹配)

我认为在 Rails 中,您需要做的是调用 strftime 来格式化将发送到 Flex 的日期输出

time_with_zone.strftime("%a %b %d %H:%M:%S %z %Y") # => "Sun Jan 03 20:58:16 +0700 2010"

From the documentation: http://www.adobe.com/livedocs/flex/3/langref/Date.html#Date()

If you pass a string to the Date class constructor, the date can be in a variety of formats, but must at least include the month, date, and year. For example, Feb 1 2005 is valid, but Feb 2005 is not. The following list indicates some of the valid formats:

Day Month Date Hours:Minutes:Seconds GMT Year (for instance, "Tue Feb 1 00:00:00 GMT-0800 2005", which matches toString())

I think in Rails, what you need to do is calling strftime to format the date output that's going to be sent to Flex

time_with_zone.strftime("%a %b %d %H:%M:%S %z %Y") # => "Sun Jan 03 20:58:16 +0700 2010"
同展鸳鸯锦 2024-08-23 19:29:57

感谢您的帮助,但奇怪的是,事实并非如此。西卡丘,你的帮助确实让我走上了正轨。我不能简单地分配返回的结果——我必须将其输入构造函数。因此,我没有这样做,但它不起作用:

var flexDate:Date = server_result.date;

我这样做了,它有效:

var flexDate:Date = new Date(server_result.date);

Thanks for the help but, oddly, that wasn't it. Your help, Sikachu, did put me on the right track. I couldn't simply assign the returned result--I had to feed it into the constructor. So, instead of doing this, which didn't work:

var flexDate:Date = server_result.date;

I did this, which works:

var flexDate:Date = new Date(server_result.date);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文