dsbckxk165039 2017-02-04 19:01
浏览 80
已采纳

从日期php中设置datepicker jquery中的日期,奇怪的值

I'm working with datepicker as follows:

<?php 

$sql="SELECT date FROM user WHERE id='$id_p' ;";
$result= query($sql);
/*Code for query in postgresql */

$date1=date_create($row['date']);
$date2=date_format($date1, 'd/m/Y');
$date3=$row['date'];
?>

<div class="form-group ">
    <label>Date *</label><br>
    <input id="date1" type="text" class="form-control required" >
    <input type="hidden" id="date3" name="datealt">
</div>

<script>
$(function () {
    $.datepicker.setDefaults($.datepicker.regional["es"]);
    $("#fechaV").datepicker({
        firstDay:1,
        currentText: 'Hoy',
        monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
        monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
        dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
        dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mié;', 'Juv', 'Vie', 'Sáb'],
        dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sá'],
        weekHeader: 'Sm',
        dateFormat: 'dd/mm/yy',
        altFormat:'yy/mm/dd'          
    });
});

var date1=<?php echo $date2;?>;
var date3=<?php echo $date3;?>;
console.log(date1);
console.log(date3);
$("#date1").attr("value", date1);
$('#date3').attr("value",date3);
</script>

My problem is that when printing the dates in the script, it takes strange values, I can notice it when printing in the console and set the datepicker. However, on seeing the code portion, I can see these have the correct value.

That is, in my code, the variables take the values:

var date1=01/01/2016;
var date3=2016-01-01;

In the console.log:

0.000496031746031746
2014

What is wrong?

PD: probably missing segments of code or some names do not match, but it was time to transcribe the code to write the problem. Sorry for my english level

  • 写回答

2条回答 默认 最新

  • douyou8266 2017-02-04 19:07
    关注

    Try this first:

    var date1="<?php echo $date2;?>";
    var date3="<?php echo $date3;?>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?