问号“?”被添加到Json请求正文中的时间字符串

时间:2019-01-18 09:46:39

标签: http datetime angular6

虽然我正在从“ BsDatepickerDirective”插件中选择一个日期,但我却将日期时间设置为“ 2019-01-01T09:28:07.000Z”格式。但这需要在传递POST请求之前将其转换为“ 04-09-2018 10:12:35:111”字符串格式。

每次我在JSON对象中传递此字符串“ 2019-01-01T09:28:07.000Z”时,我都会收到500错误,因为在 request正文中,它以某种方式更改为“ 02-01” -2019?15?:?02?:?47:000“ 还有一个问号,我不知道它从哪里来。

这是我的代码,用于将“ 2019-01-01T09:28:07.000Z”格式更改为此“ ​​2019-01-01T09:28:07.000Z”格式-

convertDateTime(value): string {
    let today = new Date(value);

    let dd = today.getDate().toString();
    let mm = (today.getMonth() + 1).toString();

    let yyyy = today.getFullYear();
    if (parseInt(dd, 10) < 10) {
      dd = '0' + dd;
    } 
    if (parseInt(mm, 10) < 10) {
      mm = '0' + mm;
    } 
    let result = dd + '-' + mm + '-' + yyyy,
        time = today.toLocaleTimeString('en-US', { hour12: false }),

        timeResult = time + ':' + '000',
        netResult = result + " " + timeResult;

    return netResult;
  }

this.convertDateTime("2019-01-01T09:28:07.000Z")

我可以看到它已成功转换为字符串“ 2019-01-01T09:28:07.000Z”格式,但仍在请求正文中显示为“ 02-01-2019?15?:?02? :?47:000“

任何人都可以告诉为什么添加问号吗?

0 个答案:

没有答案
相关问题