我正在嘗試將存儲爲時代的GMT時間轉換爲CST。將GMT時代轉換爲CST
以下是我在java中運行的當前代碼。
if (originalRFC.get("sysmodtime")!=null){
var sysmod = originalRFC.get("sysmodtime"); // Hold the sysmodtime value in a variable
logger.debug('Sysmodtime Before: ' + sysmod); // Output to log before before converstion to CST - (in GMT)
var format = new java.text.SimpleDateFormat("MMMM d, yyyy HH:mm:ss a z"); // Format the string will be in
var dateString = sysmod.toLocaleString(); // Convert the epoch to the string equivalent in CST
var parsedDate = format.parse(dateString); // Convert that CST String back to epoch
var sysmodConvert = parsedDate.getTime(); // Convert it to time and milliseconds
logger.debug('Sysmodtime After: ' + sysmodConvert); //Output to log after conversion to CST
genericRFC.setField("last-update-time",sysmodConvert);
}
請參閱在日誌中返回的錯誤之下,我們可以看到前「1301382996000」的時候,當我嘗試將它打破:
2011-05-02 14:25: 49,926 [http-8080-1] sm702-adapter_convert腳本 - Sysmodtime之前:1301382996000 2011-05-02 14:25:49,941 [http-8080-1] sm702-adapter_convert腳本 - 調用函數轉換時出錯 org.apache。 bsf.BSFException:JavaScript錯誤:java.text.ParseException:Unparseable date:「[object JavaObject]」
你的環境是什麼?我在這裏看到Java和JavaScript的奇怪混合。另外,你想如何使用轉換後的'Date',你打算格式化並顯示給用戶? – 2011-05-02 22:23:49