javascript - Bootstrap Datetimepicker set Time programmatically from Epoch - Stack Overflow

I have a simple Datetimepicker:$('#deadline_picker').datetimepicker();Trivially I can produce

I have a simple Datetimepicker:

$('#deadline_picker').datetimepicker();

Trivially I can produce the utc / or local date string with var x= new Date(timestamp) or var x= (new Date(timestamp)).toUTCString(). And Assign it as a value to the field - $('#deadline_picker').val(x)

But for one the Datetime Picker object does not seem responsive to programmatic changes (if the Calendar has a certain date selected it will still show the same date selected and it does not appear to be timezone conscious). It is very critical for me to be able to set an exact equivalent of the Epoch time programmatically. Supposedly the datetimepicker has API methods, but the docs don't have a single example.

Edit: I'm using the copy that's referenced as being currently maintained:

Edit2: Apparently it has different methods from: / But neither of them seem to have Timezone support.

I have a simple Datetimepicker:

$('#deadline_picker').datetimepicker();

Trivially I can produce the utc / or local date string with var x= new Date(timestamp) or var x= (new Date(timestamp)).toUTCString(). And Assign it as a value to the field - $('#deadline_picker').val(x)

But for one the Datetime Picker object does not seem responsive to programmatic changes (if the Calendar has a certain date selected it will still show the same date selected and it does not appear to be timezone conscious). It is very critical for me to be able to set an exact equivalent of the Epoch time programmatically. Supposedly the datetimepicker has API methods, but the docs don't have a single example.

Edit: I'm using the copy that's referenced as being currently maintained: https://github./Eonasdan/bootstrap-datetimepicker

Edit2: Apparently it has different methods from: http://www.malot.fr/bootstrap-datetimepicker/ But neither of them seem to have Timezone support.

Share Improve this question edited Nov 16, 2019 at 2:43 Cœur 38.8k25 gold badges206 silver badges278 bronze badges asked Jul 15, 2014 at 15:01 user3467349user3467349 3,2015 gold badges40 silver badges64 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

I found that one of the monly used ones at https://github./smalot/bootstrap-datetimepicker will not take (new Date).toUTCString() as an argument and is not helpful. The one I mentioned in my question: https://github./Eonasdan/bootstrap-datetimepicker - Also does not appear to take (new Date()) strings of either kind, but it will take both moment() and moment.utc() objects, so in my case this worked. (Deadline is in a table row represented visually as a Timestring without seconds, year or milliseconds, to preserve datatable space).

$td = $(this).closest('tr').children('td');
var timestamp = moment.utc($td.eq(2).attr('value')*1000);
$('#deadline_picker').data("DateTimePicker").setDate(deadline); 

This can be reversed with:

$('#deadline_picker').data("DateTimePicker").getDate().unix()

Can you try this?

    var x= (new Date(timestamp)).toUTCString();
    $('#deadline_picker').datetimepicker("update", x);

If this didnt work, try this:

    $('#deadline_picker').data({date: x});
    $('#deadline_picker').datetimepicker('update');
    $('#deadline_picker').datetimepicker().children('input').val(x);

SOURCE

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745137565a4613275.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信