在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:phstc/jquery-dateFormat开源软件地址:https://github.com/phstc/jquery-dateFormat开源编程语言:JavaScript 100.0%开源软件介绍:jquery-dateFormat - jQuery Plugin to format Date outputs using JavaScript - Having less than 5kb, jquery-dateFormat is the smallest date format library available! InstallationDownload latest jquery.dateFormat.js or jquery.dateFormat.min.js.
You can use jquery-dateFormat without jQuery. You just need to import the dateFormat.js above and instead of formatting with If you use jQuery Validate plugin you must use jquery-dateFormat without jQuery. Format patternsThe patterns to formatting are based on java.text.SimpleDateFormat. Date and time patterns
Expected input dates formats
Usage <script>
document.write($.format.date("2009-12-18 10:54:50.546", "Test: dd/MM/yyyy"));
document.write($.format.date("Wed Jan 13 10:43:41 CET 2010", "dd~MM~yyyy"));
</script> Output
Formatting using css classes <span class="shortDateFormat">2009-12-18 10:54:50.546</span>
<span class="longDateFormat">2009-12-18 10:54:50.546</span> jQuery(function() {
var shortDateFormat = 'dd/MM/yyyy';
var longDateFormat = 'dd/MM/yyyy HH:mm:ss';
jQuery(".shortDateFormat").each(function (idx, elem) {
if (jQuery(elem).is(":input")) {
jQuery(elem).val(jQuery.format.date(jQuery(elem).val(), shortDateFormat));
} else {
jQuery(elem).text(jQuery.format.date(jQuery(elem).text(), shortDateFormat));
}
});
jQuery(".longDateFormat").each(function (idx, elem) {
if (jQuery(elem).is(":input")) {
jQuery(elem).val(jQuery.format.date(jQuery(elem).val(), longDateFormat));
} else {
jQuery(elem).text(jQuery.format.date(jQuery(elem).text(), longDateFormat));
}
});
}); Output
Pretty date formatting
jQuery.format.prettyDate(new Date()) // => "just now"
jQuery.format.prettyDate(new Date().getTime()) // => "just now"
jQuery.format.prettyDate("2008-01-28T20:24:17Z") // => "2 hours ago"
jQuery.format.prettyDate("2008-01-27T22:24:17Z") // => "Yesterday"
jQuery.format.prettyDate("2008-01-26T22:24:17Z") // => "2 days ago"
jQuery.format.prettyDate("2008-01-14T22:24:17Z") // => "2 weeks ago"
jQuery.format.prettyDate("2007-12-15T22:24:17Z") // => "more than 5 weeks ago" toBrowserTimeZone
Valid input formats var date1 = "2013-09-14T23:22:33Z";
var date2 = "2013-09-14T16:22:33.527-07:00";
var date3 = "Sat Sep 14 2013 16:22:33 GMT-0700 (PDT)";
$.format.toBrowserTimeZone(date1)
$.format.toBrowserTimeZone(date2)
$.format.toBrowserTimeZone(date3) DevelopmentTo compile jquery-dateFormat (generate dist files): npm run compile TestingTests are written using Jasmine. To run the test suite with PhantomJS, run Licensesjquery-dateFormat is released under the MIT License. Do you want to improve jquery-dateFormatYou're welcome to make your contributions and send them as a pull request. ContributorsThanks to all contributors. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论