小编All*_*nto的帖子

bootstrap-datetimepicker将选定的本地日期转换为UTC

我使用来自http://tarruda.github.io/bootstrap-datetimepicker/的 bootstrap-datetimepicker 这给出了选择当地时间的日期时间的选项,我无法理解的是如何在将它发送到cgi之前将其转换为UTC .我需要这样做,因为我的服务器设置为GMT时区,输入可以来自任何时区.
所以我希望用户在他的tz中选择时间,但将该选择转换为gmt,将其发送到我的cgi脚本.
如果有任何其他更好的方法来解决这个问题,我也会很感激.

<script type="text/javascript">
    $('#timetime').datetimepicker({
        maskInput: true,
        format: 'yyyy-MM-dd hh:mm',
    });
</script>
Run Code Online (Sandbox Code Playgroud)

它是在下面的代码中的表单中调用的

<label for="sdate" class="control-label">* Scheduled Date (UTC/GMT)</label>
<div id="timetime" class="controls">
    <input id="sdate" name="sdate" type="text" placeholder="YYYY-MM-DD HH:MM"></input>
    <span class="add-on">
        <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
    </span>
</div>
Run Code Online (Sandbox Code Playgroud)

最终答案基于电影提供者的帮助

<script type="text/javascript">
            $('#timetime').datetimepicker({
                            maskInput: true,
                          format: 'yyyy-MM-dd hh:mm',
                          });

$("form").submit(function(){
   // Let's find the input to check
   var $input = $(this).find("input[name=sdate]");
   if ($input.val()) {
  // Value is falsey (i.e. null), lets set a new one, i have inversed this, …
Run Code Online (Sandbox Code Playgroud)

javascript

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

javascript ×1