Formatting a date in javascript till the millisecond

巧了我就是萌 提交于 2019-12-23 06:57:01

问题


We are using the following js lib from Microsoft https://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js

var datetimehigh = new Date(2011,01,12,14,45,55,596);

var sDate =  datetimehigh.format("dd/MM/yyyy HH:mm:ss sss");

I cannot get the millisecond part to work.Note that format comes from Microsoft's Mvc Ajax lib.


回答1:


It's indicated by an f:

"dd/MM/yyyy HH:mm:ss fff"



回答2:


Using the date format library, it should be something like this:

var nowMilliseconds = new Date().format("yyyy-mm-dd HH:MM:ss l");

http://blog.stevenlevithan.com/archives/date-time-format

L for milliseconds with two digits

l (minus) for milliseconds with three digits




回答3:


Use 'S' for milliseconds formatting:

"dd/MM/yyyy HH:mm:ss:SSS"


来源:https://stackoverflow.com/questions/9212889/formatting-a-date-in-javascript-till-the-millisecond

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!