Javascript examples for Date Operation:Date Format
Change date format string by a function and string replace
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/* w w w. j a va 2 s . co m*/ function validateDateFormat(s) { if(s.indexOf('yyyy') > -1) return s.replace('yyyy','yy'); return s.replace('yy','y'); } console.log(validateDateFormat('dd/mm/yyyy')); // "dd/mm/yy" console.log(validateDateFormat('dd/mm/yy')); // "dd/mm/y" } </script> </head> <body> </body> </html>