简体   繁体   English

将变量传递给jQuery DateTimePicker进行格式化?

[英]Passing a variable to jQuery DateTimePicker for formating?

I am trying to use the jQuery plugin DateTimePicker to format a DateTime varabile but I can't figure out how to apply the formatting command to a variable. 我正在尝试使用jQuery插件DateTimePicker格式化DateTime变量,但是我不知道如何将格式化命令应用于变量。 All the examples I find are how to apply it to a DOM element which will not work for me. 我发现的所有示例都是如何将其应用于对我不起作用的DOM元素。 Does anyone know how to do this? 有谁知道如何做到这一点? The last code snip I have from my hours of trying things out is 我花了很多时间尝试的最后一个代码片段是

obj.colModel[9].render = function (ui)
{
    var cellData = new Date(ui.cellData);
    return $.datetimepicker({ dateFormat: "yy-mm-dd", timeFormat: "hh:mm:ss" }, cellData);
}

As answered by the creator at https://github.com/trentrichardson/jQuery-Timepicker-Addon/issues/862 the code to do this is: 正如创建者在https://github.com/trentrichardson/jQuery-Timepicker-Addon/issues/862回答的那样,执行此操作的代码是:

var dateObj = new Date(ApprovalDate);
var dateStr = $.datepicker.formatDate( "yy-mm-dd", dateObj );
var timeStr = $.datepicker.formatTime('HH:mm', { hour: dateObj.getHours(), minute: dateObj.getMinutes() }, {});

var dateTimeStr = dateStr +' '+ timeStr;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM