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条)

报告相同问题?

悬赏问题

  • ¥15 软件定义网络mininet和onos控制器问题
  • ¥15 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。