¿Cómo puedo formatear la fecha usando jQuery? Estoy usando el siguiente código pero obtengo un error:
$("#txtDate").val($.format.date(new Date(), 'dd M yy'));Sugiera una solución.
agregue el complemento jquery ui en su página.
$("#txtDate").val($.datepicker.formatDate('dd M yy', new Date()));jQuery dateFormat es un complemento separado. Debe cargar eso explícitamente usando una etiqueta <script> .
Una alternativa sería la función js date() simple, si no desea utilizar el complemento jQuery/jQuery:
p.ej:
var formattedDate = new Date("yourUnformattedOriginalDate"); var d = formattedDate.getDate(); var m = formattedDate.getMonth(); m += 1; // JavaScript months are 0-11 var y = formattedDate.getFullYear(); $("#txtDate").val(d + "." + m + "." + y);ver: 10 formas de formatear la hora y la fecha usando JavaScript
Si desea agregar ceros iniciales al día/mes, este es un ejemplo perfecto: Javascript agrega ceros iniciales a la fecha
y si desea agregar tiempo con ceros a la izquierda, intente esto: getMinutes () 0-9: ¿cómo con dos números?