Posted By


shinokada on 01/18/11

Tagged


Statistics


Viewed 647 times
Favorited by 0 user(s)

convert_date_to_human_readable


/ Published in: JavaScript
Save to your folder(s)

From webworks, book "CMS Design Using Php and jQuery", page 93


Copy this code and paste it in your HTML
  1. function convert_date_to_human_readable(){
  2. var $this=$(this);
  3. var id='date-input-'+Math.random().toString()
  4. .replace(/\./,'');
  5. var dparts=$this.val().split(/-/);
  6. $this
  7. .datepicker({
  8. dateFormat:'yy-mm-dd',
  9. modal:true,
  10. altField:'#'+id,
  11. altFormat:'DD, d MM, yy',
  12. onSelect:function(dateText,inst){
  13. this.value=dateText;
  14. }
  15. });
  16. var $wrapper=$this.wrap(
  17. '<div style="position:relative" />');
  18. // Usage this in html,php
  19. //<input name="associated_date" class="date-human" value="',$page['associated_date'],'" />
  20. //...
  21.  
  22. var $input=$('<input id="'+id+'" class="date-human-readable"
  23. value="'+date_m2h($this.val())+'" />');
  24. $input.insertAfter($this);
  25. $this.css({
  26. 'position':'absolute',
  27. 'opacity':0
  28. });
  29. $this
  30. .datepicker(
  31. 'setDate', new Date(dparts[0],dparts[1]-1,dparts[2])
  32. );
  33. }
  34. $(function(){
  35. $('input.date-human').each(convert_date_to_human_readable);
  36. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.