dongmo8943 2018-06-22 09:33
浏览 41

Internet Explorer 11 / Microsoft Edge中的碳错误

I've recently discovered that my website produces error in Internet Explorer 11 and Microsoft Edge. Works well on all other browsers.

Error occures, when im using Carbon to create a date in Laravel.

Code:

$date = new Carbon(request('date'));

request('date') is like "YYYY-mm-dd", and its working perfectly in other browsers.

Error I get on this line is:

DateTime::__construct(): Failed to parse time string (‎2018-‎06-‎13) at position 0 (�): Unexpected character

I've tried a lot of other methods, to create the Carbon instance, all working fine in other borsers, but not in these.

Any idea, what could couse the problem?

EDIT: The data sent by the javascript is a string in this case "2018-06-13". I've tried to explode the string, and reconnect again, and convert some other ways. It says string(10) "2018-06-13" in most of the browsers, and string(19) "‎2018-‎06-‎13" in internet explorer, which is really wierd.

EDIT2: Script for creating the days for the calendar (Vue2.js):

weeks: function () {
            var dayCount = this.calendar.days(this.displayedYear, this.displayedMonth),
                dayIndex = this.calendar.day(this.displayedYear, this.displayedMonth, 0).getDay(),
                weekCount = Math.ceil((dayCount + dayIndex) / 7);

            var weeks = [];

            for (var i = 0; i < weekCount; i++) {
                var week = [];

                for (var j = 0; j < 7; j++) {
                    var date = new Date(
                        this.displayedYear,
                        this.displayedMonth - 1,
                        i * 7 + j - dayIndex + 1
                    );

                    week.push(
                        date.getMonth() === this.displayedMonth - 1
                            ? date : null
                    );
                }

                weeks[i] = week;
            }

            return weeks;

Blade for displaying:

<tr v-for="week in weeks()">
                <td
                        v-for="day in week"
                        @click="setSelectionPivot(day)"
                        :class="classes(day)">
                    <span>
                        @{{ (day == null) ? '' : day.getDate() }}
                    </span>
                </td>
            </tr>

Function part to process:

this.selection = day;

Then I pass this with ajax to the code the error occures. Ask if anything else is needed. The thing I don't understand is how it works perfectly in any other browser?

  • 写回答

2条回答 默认 最新

  • dongshen6060 2018-06-22 11:01
    关注

    First thing is to check which browser client is using if it is Internet Explorer 11/Microsoft Edge then parse date like this:

    $req->time->toDateTime()->format('d-m-Y H:i:s A')    //I assume you already get time value from view
    

    To check which browser client is using follow this link:PHP function to get browser

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用