Javascript 哪种最简单的方式可以将日期时间显示到分钟?
我有一个“datetime local”类型的输入字段。当我给它分配当前时间戳时,输入字段也显示秒和毫秒。什么是最简单的方式来显示只有分钟的时间Javascript 哪种最简单的方式可以将日期时间显示到分钟?,javascript,angularjs,datetime,Javascript,Angularjs,Datetime,我有一个“datetime local”类型的输入字段。当我给它分配当前时间戳时,输入字段也显示秒和毫秒。什么是最简单的方式来显示只有分钟的时间 <body ng-controller="MainCtrl"> <input type="datetime-local" class="form-control" id="DateTime" ng-model="formInfo.dateTime"> </body> 以下是当前使用的浏览器实现的
<body ng-controller="MainCtrl">
<input type="datetime-local" class="form-control" id="DateTime" ng-model="formInfo.dateTime">
</body>
以下是当前使用的浏览器实现的日期时间选择器。鉴于这不是跨浏览器的标准,如果不使用另一个或为日期时间选择器提供一致的api,据我所知,日期时间输入类型根本没有任何与之关联的选项。下面是如何轻松格式化Date()类型的,尽管在我注意到您谈论的是浏览器实现的日期时间选择器的显示之前,我已经发布了它 格式历史参考 toString().split().slice().join() 这可能不如使用它提供的某些函数格式化它那样有效。不过这很简单
var a=(new Date()).toString().split(“”).slice(0,5).join(“”);
文件。编写(a)代码>尝试使用格式化模型内容
或者如果您使用的是角度日期选择器
您已经有了格式化日期的指令
<input type="datetime" format="dd MMM yyyy" >
使用Sandeep在评论中建议的日期过滤器:
<body ng-app="plunker" ng-controller="MainCtrl">
<input type="text" class="form-control" id="DateTime" placeholder="Enter the date and time of consumption" ng-model="formInfo.dateTime| date:'yyyy-MM-dd hh:mm'">
</body>
为什么不使用日期过滤器的可能重复查看此plunker@Sandeep,谢谢您提供的信息,但我也想知道时间,而且时间也只有几分钟。但是我们无法简单地分配$scope.formInfo.dateTime=a
啊,是的。。。实际上,输入的显示就是他想要更改的内容=/。。。考虑到datepicker是由所使用的浏览器实现的,所以不确定是否可以这样做。
<body ng-app="plunker" ng-controller="MainCtrl">
<input type="text" class="form-control" id="DateTime" placeholder="Enter the date and time of consumption" ng-model="formInfo.dateTime| date:'yyyy-MM-dd hh:mm'">
</body>