在将日期转换为oracle日期格式时打印日期

时间:2016-12-06 16:54:51

标签: javascript oracle date

我正在将javascript日期转换为oracle日期格式,并继续打印旧日期。请考虑以下代码。我希望13-DEC-2016能够在alert ("Printing Full Date: "+fullStartOracleDate);对话框中打印,但由于某种原因,它会继续打印2-DEC-2016。它在JSFiddle here.

中得到了证明
var assignedOnDate = "12/13/2016";
var  myJSDate = new Date(assignedOnDate);


alert ("Printing Date: "+assignedOnDate);

var monthNames =  ["JAN", "FEB", "MAR", "APR", "MAY", "JUN",
                "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ];

  var month = myJSDate.getMonth();
  var year = myJSDate.getFullYear();
  var day = myJSDate.getDay();

  var fullStartOracleDate  = day+"-"+monthNames[month]+"-"+year;

  alert ("Printing Full Date: "+fullStartOracleDate);

1 个答案:

答案 0 :(得分:1)

使用getDate for day

var assignedOnDate = "12/13/2016"; var myJSDate = new Date(assignedOnDate); alert ("Printing Date: "+assignedOnDate); var monthNames = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ]; var month = myJSDate.getMonth(); var year = myJSDate.getFullYear(); var day = myJSDate.getDate(); var fullStartOracleDate = day+"-"+monthNames[month]+"-"+year; alert ("Printing Full Date: "+fullStartOracleDate);