简体   繁体   English

如何在JavaScript中修剪日期+时间字符串的时间部分

[英]How to trim time part of a date+time string in javascript

I am receiving json data in my javascript as a list of strings that contain date and time of certain events. 我正在JavaScript中以包含某些事件的日期和时间的字符串列表的形式接收json数据。

I construct an array and store these in the array. 我构造一个数组并将其存储在数组中。

However the storage is in the format of dd/mm/yyyy hh:mm:ss. 但是,存储格式为dd / mm / yyyy hh:mm:ss。 I was wondering if there is a way to just extract the date part of this string from the array. 我想知道是否有一种方法可以从数组中提取此字符串的日期部分。

// run a loop to parse thru all elements in the array. //
t = (Service_date_from[count]); // 't' is what contains the date time once extracted from the array with a counter variable called `count`

Is there any kind of date formating functionality in javascript? javascript中是否有任何日期格式化功能?

If it's always formatted that way, you can simply use substr 如果始终采用这种格式,则只需使用substr

var idx = t.indexOf(" ");
var timeStr = t.substr(idx + 1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM