【问题标题】:Remove GMT+530(Indian standard Time) without changing current time in javascript删除 GMT+530(印度标准时间)而不更改 javascript 中的当前时间
【发布时间】:2016-10-24 11:38:28
【问题描述】:

我正在像这样显示当前日期、月份、日期、年份和时间

Mon Oct 24 2016 17:09:25 GMT+0530 (India Standard Time)​​​​​​​ 

但我需要这样显示

Mon Oct 24 2016 17:09:25
我的 javascript 代码:

var timestamp = new Date();
editor.insertHtml( 'The current date and time is: ' + timestamp.toString());

我该怎么做,请谁能告诉我怎么做。

谢谢

【问题讨论】:

  • timestamp.toString().split('+')[0]
  • 你在哪里 timestamp.toString() 将其替换为 timestamp.toString().split('+')[0]
  • 嗨,Mon Oct 24 2016 17:27:06 GMT 是这样的,但我不需要显示 GMT 也请告诉我

标签: javascript asp.net


【解决方案1】:

如果你愿意添加一个库,你应该使用moment.js

console.log(moment().format('ddd MMM DD YYYY hh:mm:ss'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/moment.min.js"></script>

如果没有,请稍作解决

var d = new Date().toString();
var index = d.lastIndexOf(':') +3
console.log(d.substring(0, index))

注意:更倾向于矩法

【讨论】:

  • 谢谢,它会正常工作的。但我需要10/24/2016 格式是否可能
  • 你可以通过moment().format('MM/DD/YYYY')实现它
【解决方案2】:
var date = new Date();
var n = d.toLocaleString();
document.getElementById("demo").innerHTML = n;

这对我有用。

【讨论】:

    【解决方案3】:

    var timestamp = new Date();
    
    console.log(
      timestamp.toString().split('GMT')
    )
    // Mon Oct 25 2021 17:56:11 GMT+0530 (India Standard Time)` 

    输出将是 Mon Oct 25 2021 17:55:02

    【讨论】:

      【解决方案4】:

      let today = new Date();
      today = today.toString();
      today = today.split('G')[0];
      console.log(today);

      【讨论】:

        猜你喜欢
        • 2020-05-02
        • 2015-12-17
        • 2013-10-03
        • 2015-03-08
        • 2010-10-05
        • 1970-01-01
        • 2020-09-14
        • 1970-01-01
        • 2012-03-27
        相关资源
        最近更新 更多