2015-09-23 35 views
1

如果我在我的頁面中有一個html控件。Sitecore:在<type input =「text」>類型=「DateTime」的sitecore字段中保存日期>

<input type="text" id="dateFrom" runat="server" ClientIDMode="Static"/> 

點擊一個按鈕,我省輸入dateFrom的一個Sitecore的項目與類型字段中的值 「DateTime

代碼隱藏:

item["Visible From"] = dateFrom.Value; 

我使用jQuery來顯示用戶點擊輸入框內的日曆dateFrom

$(function() { 
     $("#dateFrom").datepicker(); 
    }); 

保存項目後,我在「內容編輯器」看到的結果是: enter image description here

正確的日期是一些如何不節能。我也試過用<asp:TextBox 而不是<input type="text",但結果仍然一樣。

回答

8

日期存儲在ISO在後端8601格式,使用Sitecore的輔助方法來讓它進入正確的格式:

var dateTime = DateTime.Parse(dateFrom.Value); 
var isoDate = DateUtil.ToIsoDate(dateTime); 
item["Visible From"] = isoDate ; 

您可以這篇文章Using DateTime And Date Fields In Sitecore

0

中獲取更多日期以自己的(基於字符串)格式存儲在Sitecore中。你可以檢查,如果你從上面的菜單檢查查看 - > Raw Vales

Sitecore擁有自己的助手類,名爲DateUtil來處理日期和時間。

string storedDateTimeValue = DateUtil.DateTimeToIsoDate(DateTime.Now); 

或反向操作:對DateUtil類API

DateTime dt = DateUtil.IsoDateToDateTime(storedDateTimeValue); 

Here is有點過時,但正確的信息。

相關問題