将PHP date()样式的dateFormat转换为等效的jQuery UI datepicker字符串

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将PHP date()样式的dateFormat转换为等效的jQuery UI datepicker字符串相关的知识,希望对你有一定的参考价值。

This is a simple bit of code that allows you to do a write once date format in a php style date() format and convert it to be used by datepicker jQuery UI widget. It returns the converted string. Nothing fancy here, but a time saver for the future. Could use improvement such as error handling for common PHP dateFormat string values that do not have an equivalent UI portion. Potentially make this a two way conversion. Add more available options.
  1. function dateStringToDatepickerFormat($dateString)
  2. {
  3. $pattern = array(
  4.  
  5. //day
  6. 'd', //day of the month
  7. 'j', //3 letter name of the day
  8. 'l', //full name of the day
  9. 'z', //day of the year
  10.  
  11. //month
  12. 'F', //Month name full
  13. 'M', //Month name short
  14. 'n', //numeric month no leading zeros
  15. 'm', //numeric month leading zeros
  16.  
  17. //year
  18. 'Y', //full numeric year
  19. 'y' //numeric year: 2 digit
  20. );
  21. $replace = array(
  22. 'dd','d','DD','o',
  23. 'MM','M','m','mm',
  24. 'yy','y'
  25. );
  26. foreach($pattern as &$p)
  27. {
  28. $p = '/'.$p.'/';
  29. }
  30. return preg_replace($pattern,$replace,$dateString);
  31. }

以上是关于将PHP date()样式的dateFormat转换为等效的jQuery UI datepicker字符串的主要内容,如果未能解决你的问题,请参考以下文章

java string转化成date的问题

如何用Java把date类型转换成long数字?

java怎么将String转换成日期

java的date怎么转换成utc

java string类型怎么转化成date类型

JAVA_Converter_字符串类型转Date类型