2010-01-03 51 views
2

我收到以下錯誤: TypeError:錯誤#1034:類型強制失敗:無法將「2010-01-02 23:28:17 UTC」轉換爲日期。從Rails到Flex的日期/時間轉換問題?

我使用WebORB在Rails和Flex之間傳輸數據。來自Rails的數據類型爲:'ActiveSupport :: TimeWithZone'。我正在嘗試將其分配給Flex'Date'數據類型。

我錯過了什麼?

+0

你能告訴我們你正在使用嘗試和轉換代碼的例子這次?這將是非常有用的 – 2010-01-03 13:20:48

回答

1

感謝但是,奇怪的是,那不是。你的幫助,錫卡丘,確實讓我走上了正軌。我不能簡單地分配返回的結果 - 我必須將其饋送到構造函數中。所以,與其這樣做,沒有工作:

var flexDate:Date = server_result.date; 

我這樣做,它的工作原理:

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

從文檔: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())

我認爲Rails中,你需要做的就是調用strftime格式化那將要發送的日期輸出什麼到Flex

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