0

我有幾個引導日期時間選擇器,並試圖使用從數據庫讀取的數據從服務器設置文本框和選定的日期和時間。它一直將其設置爲今天的上午12:00。Bootstrap datetimepicker - 設置日期時間服務器端

這是我上面的.aspx和.aaspx.cs文件內容:

$(document).ready(function() { 
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); 
    Sys.WebForms.PageRequestManager.getInstance().beginAsyncPostBack(); 
    function EndRequestHandler(sender, args) { 
     $('#tpStartDate').datetimepicker({ 
      sideBySide: true, 
      ignoreReadonly:true, 
      daysOfWeekDisabled:[0,6] 
     }); 
     $('#tpEndDate').datetimepicker({ 
      sideBySide: true, 
      ignoreReadonly:true, 
      daysOfWeekDisabled:[0,6] 
     }); 
    } 
}); 
<div class="col-sm-3 col-md-3"> 
    <div class="form-group"> 
     <label for="title">Start Date</label> 
     <div class="input-group date" id="tpStartDate"> 
      <input runat="server" id="tbStartDateTime" type="text" class="form-control" readonly="readonly" style="cursor:pointer" /> 
      <span class="input-group-addon"> 
       <span class="glyphicon glyphicon-calendar" style="cursor:pointer"></span> 
      </span> 
     </div> 
    </div> 
</div> 

的.cs:

tbStartDateTime.Value = dtClassList.Rows[0]["StartDateTime"].ToString(); 
tbEndDateTime.Value = dtClassList.Rows[0]["EndDateTime"].ToString(); 

當我把上面的斷點,我看到的啓動日期時間是「 2017/8/23 1:30:00 PM「並且結束日期時間爲」2017/8/23 3:00:00 PM「,但在頁面上它們都顯示爲」10/17/2017 12:00 AM「 (今天的日期)

回答

0

爲此,您必須設置爲選項useCurrent: false as默認useCurrent爲真。

如果你沒有設置它將始終啓動與當前日期和時間頁面上的選擇器。

,但它們都顯示爲 「2017年10月17日12:00 AM」 (今天的日期),在頁面上

這是一個古老的錯誤:https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1311

這是解決最新版本我建議你使用V 4.17.47

+0

我有4.14.30版本。我嘗試了4.17.47,但它使樣式變得混亂,它可能不適合Bootstrap 3.3.7,這正是我所擁有的。但設置useCurrent:false似乎已解決了我的問題。謝謝。 – NoBullMan

+0

這就是風格,因爲我使用BS 3.3.7,以防萬一記得更新你的CSS樣式(庫的)與版本碰撞太多,這種方式不會破壞任何東西 –

相關問題