如何从 JavaScript 日期中删除时间部分?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34722862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I remove time part from JavaScript date?
提问by Phill Greggan
I have a date '12/12/1955 12:00:00 AM'
stored in a hidden column. I want to display the date without the time. How do I do this?
我有一个'12/12/1955 12:00:00 AM'
存储在隐藏列中的日期。我想显示没有时间的日期。我该怎么做呢?
采纳答案by Ibrahim Khan
Split it by space
and take first part like below. Hope this will help you.
将其拆分space
并采用如下所示的第一部分。希望这会帮助你。
var d = '12/12/1955 12:00:00 AM';
d = d.split(' ')[0];
console.log(d);
回答by Cerbrus
回答by Vijay Jagdale
This is probably the easiest way:
这可能是最简单的方法:
new Date(<your-date-object>.toDateString());
Example: To get the Current Date without time component:
示例:要获取没有时间组件的当前日期:
new Date(new Date().toDateString());
gives: Thu Jul 11 2019 00:00:00 GMT-0400 (Eastern Daylight Time)
给出:2019 年 7 月 11 日星期四 00:00:00 GMT-0400(东部夏令时间)