javascript - php dateformat to moment js format -
i have got config php dateformats
'dateformat' => 'd.m.y', 'timeformat' => 'h:i', 'datetimeformat' => 'd.m.y h:i',
but datetimepicker need moment.js formatting (http://momentjs.com/docs/#/displaying/format/) so:
dd.mm.yyyy hh:mm dd.mm.yyyy hh:mm
this no problem me replace d
dd
, m
mm
wondering if nobody before has built this.
so wrote litte helper function convert php dateformats format needed moment.js
function convertphptomomentformat($format) { $replacements = [ 'd' => 'dd', 'd' => 'ddd', 'j' => 'd', 'l' => 'dddd', 'n' => 'e', 's' => 'o', 'w' => 'e', 'z' => 'ddd', 'w' => 'w', 'f' => 'mmmm', 'm' => 'mm', 'm' => 'mmm', 'n' => 'm', 't' => '', // no equivalent 'l' => '', // no equivalent 'o' => 'yyyy', 'y' => 'yyyy', 'y' => 'yy', 'a' => 'a', 'a' => 'a', 'b' => '', // no equivalent 'g' => 'h', 'g' => 'h', 'h' => 'hh', 'h' => 'hh', 'i' => 'mm', 's' => 'ss', 'u' => 'sss', 'e' => 'zz', // deprecated since version 1.6.0 of moment.js 'i' => '', // no equivalent 'o' => '', // no equivalent 'p' => '', // no equivalent 't' => '', // no equivalent 'z' => '', // no equivalent 'c' => '', // no equivalent 'r' => '', // no equivalent 'u' => 'x', ]; $momentformat = strtr($format, $replacements); return $momentformat; }
Comments
Post a Comment