Skip to content

jquery-dateFormat - it’s a jQuery Plugin that I made to formatting java.util.Date.toString output using JavaScript

Notifications You must be signed in to change notification settings

tukutela/jquery-dateFormat

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jquery-dateFormat - it’s a jQuery Plugin that I made to formatting java.util.Date.toString output using JavaScript

This plugin is also available on jQuery Plugin page

plugins.jquery.com/project/jquery-dateFormat

Blog post to explain the plugin usage

pablocantero.com/blog/2010/09/04/jquery-plugin-javascript-for-java-util-date-tostring-format/

Format patterns

The patterns to formatting are based on java.text.SimpleDateFormat

download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html

Date and time patterns

  • yyyy = year

  • MM = month

  • MMM = month abbreviation (Jan, Feb … Dec)

  • dd = day

  • hh = hour in am/pm (1-12)

  • HH = hour in day (0-23)

  • mm = minute

  • ss = second

  • a = am/pm marker

Expected input dates formats

  • 2009-12-18 10:54:50.546 (default java.util.Date.toString output)

  • Wed Jan 13 10:43:41 CET 2010 (???)

  • 2010-10-19T11:40:33.527+02:00 (default JAXB formatting of java.util.Date)

  • Sat Mar 05 2011 11:47:35 GMT-0300 (BRT) (default JavaScript new Date().toString() output)

Examples

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>

output

#1 18/12/2009
#2 18/12/2009 10:54:50

Formatting using JavaScript

<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

#1 Test: 18/12/2009
#2 18~12~2009

Tips

The css class names patterns by default are

  • shortDateFormat = dd/MM/yyyy

  • longDateFormat = dd/MM/yyyy hh:mm:ss

You can change the patterns in jquery.dateFormat

Test

This plugin was developed using jsunittest.com

Open Test.html in Firefox to run the entire test suite

Do you want to improve jquery-dateFormat

You’re welcome to make your contributions and send them as a pull request

Contributors

Thanks to jafin, docchang, eemeyer, jakemonO, jharting, christopherstott, larryzhao, albertjan

About

jquery-dateFormat - it’s a jQuery Plugin that I made to formatting java.util.Date.toString output using JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published