Announcement

Collapse
No announcement yet.

Bug in Date Object???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bug in Date Object???

    The function below is returning the wrong month (05 instead of 06 when run on 6/17/2009)

    Is this a bug, or am I doing something wrong?

    Thanks,
    Greg

    // Function Creates a String of Current UTC Date and Time
    function fGetUTCDateTime()
    {
    var sTmp = null;
    var now = new Date();
    var nYear = now.getUTCFullYear();
    // TODO Find out why this gives the wrong month
    var nMonth = now.getUTCMonth();
    var nDay = now.getUTCDate();
    var nHour = now.getUTCHours();
    var nMinute = now.getUTCMinutes();
    var nSecond = now.getUTCSeconds();
    // Create String Representation of UTC DateTime
    var sYear = String(nYear);
    if (nMonth < 10)
    {
    var sMonth = "0" + String(nMonth);
    } // endif
    else
    {
    var sMonth = String(nMonth);
    } // end else
    if (nDay < 10)
    {
    var sDay = "0" + String(nDay);
    } // endif
    else
    {
    var sDay = String(nDay);
    } // end else
    if (nHour < 10)
    {
    var sHour = "0" + String(nHour);
    } // endif
    else
    {
    var sHour = String(nHour);
    } // end else
    if (nMinute < 10)
    {
    var sMinute = "0" + String(nMinute);
    } // endif
    else
    {
    var sMinute = String(nMinute);
    } // end else
    if (nSecond < 10)
    {
    var sSecond = "0" + String(nSecond);
    } // endif
    else
    {
    var sSecond = String(nSecond);
    } // end else
    sTmp = sYear + sMonth + sDay + "-" + sHour + ":" + sMinute + ":" + sSecond;
    return(sTmp);
    } // end fGetUTCDateTime

  • #2
    Re: Bug in Date Object???

    Greg
    That is not a bug. Months in the JavaScript Date Object are numbered from 0 (January) to 11 (December)
    Alex


    Originally posted by GregSchroeder
    The function below is returning the wrong month (05 instead of 06 when run on 6/17/2009)

    Is this a bug, or am I doing something wrong?

    Thanks,
    Greg

    // Function Creates a String of Current UTC Date and Time
    function fGetUTCDateTime()
    {
    var sTmp = null;
    var now = new Date();
    var nYear = now.getUTCFullYear();
    // TODO Find out why this gives the wrong month
    var nMonth = now.getUTCMonth();
    var nDay = now.getUTCDate();
    var nHour = now.getUTCHours();
    var nMinute = now.getUTCMinutes();
    var nSecond = now.getUTCSeconds();
    // Create String Representation of UTC DateTime
    var sYear = String(nYear);
    if (nMonth < 10)
    {
    var sMonth = "0" + String(nMonth);
    } // endif
    else
    {
    var sMonth = String(nMonth);
    } // end else
    if (nDay < 10)
    {
    var sDay = "0" + String(nDay);
    } // endif
    else
    {
    var sDay = String(nDay);
    } // end else
    if (nHour < 10)
    {
    var sHour = "0" + String(nHour);
    } // endif
    else
    {
    var sHour = String(nHour);
    } // end else
    if (nMinute < 10)
    {
    var sMinute = "0" + String(nMinute);
    } // endif
    else
    {
    var sMinute = String(nMinute);
    } // end else
    if (nSecond < 10)
    {
    var sSecond = "0" + String(nSecond);
    } // endif
    else
    {
    var sSecond = String(nSecond);
    } // end else
    sTmp = sYear + sMonth + sDay + "-" + sHour + ":" + sMinute + ":" + sSecond;
    return(sTmp);
    } // end fGetUTCDateTime

    Comment


    • #3
      Thanks !!!

      Comment


      • #4
        Greg
        My pleasure
        Alex


        Originally posted by GregSchroeder
        Thanks !!!

        Comment

        Working...
        X