【问题标题】:How to convert digits in format "hhmmss" to time format hh:mm:ss using javascript? [closed]如何使用javascript将“hhmmss”格式的数字转换为时间格式hh:mm:ss? [关闭]
【发布时间】:2016-10-26 11:21:59
【问题描述】:

我有080000 之类的字符串,我想使用javascript 或jquery 将其更改为08:00:00 之类的时间格式(如字符串类型的日期格式)。我该怎么做?

【问题讨论】:

  • 我认为字符串应该是080000,因为小时可以是两位数。
  • 是的..但是如何实现解决方案..

标签: javascript string time time-format


【解决方案1】:

您可以使用String.prototype.match() 中的正则表达式轻松地将字符串拆分为两位数,该正则表达式返回数组中的值。然后使用Array.prototype.join() 将数组项连接成字符串。

var str = "080000";
str = str.match(/\d{2}/g).join(":");
console.log(str);

【讨论】:

    猜你喜欢
    • 2014-04-22
    • 1970-01-01
    • 2017-01-06
    • 1970-01-01
    • 1970-01-01
    • 2023-02-04
    • 1970-01-01
    • 2018-09-08
    • 2013-04-24
    相关资源
    最近更新 更多