Java SimpleDateFormat Pattern for JavaScript Date

前端 未结 4 1645
时光说笑
时光说笑 2020-12-07 03:04

I need to convert a Java Date object to a string that is the same format as JavaScript Dates when they are converted to a string. On our server we have JavaScript dates that

4条回答
  •  醉话见心
    2020-12-07 03:50

    Typically if a given date is valid then the date object created should return back the same date, month and year value. Below logic worked for most of the cases that I coded.

    Example: 29-Feb-2018 does not exist, but when javascript accepts this input as Date("2018-02-29") it creates a date value of 1-Mar-2018.

    Javascript Function:

        function dateCheck(dd,mm,yyyy)
        {
          var tempDt = new Date(parseInt(yyyy), parseInt(mm)-1, parseInt(dd), 0, 0, 0, 0);
    
          if(tempDt.getDate()!=parseInt(dd) ||
            tempDt.getFullYear()!=parseInt(yyyy) ||
            tempDt.getMonth() + 1 !=parseInt(mm))
            return false;
          else
            return true;
        }
    

提交回复
热议问题