change date format from jquery

前端 未结 3 2009
野性不改
野性不改 2020-12-11 08:33

I have this date, that I get from jquery

Wed Oct 30 2013 09:05:17 GMT-0800 (Hora estándar Pacífico (México))

that I get this function

相关标签:
3条回答
  • 2020-12-11 08:59

    A couple of options.

    If you're OK with including jQueryUI: $("#vigencia_receta_11").val($.datepicker.formatDate('dd/M/yy', nd));

    Otherwise, the jQuery dateFormat plugin does something similar: $("#vigencia_receta_11").val($.format.date(nd, 'dd/M/yy'));

    0 讨论(0)
  • 2020-12-11 09:14

    I did like the following code:

    function myDateFormatter ("pass your date here") {
            var d = new Date(dateObject);
            var day = d.getDate();
            var month = d.getMonth() + 1;
            var year = d.getFullYear();
            if (day < 10) {
                day = "0" + day;
            }
            if (month < 10) {
                month = "0" + month;
            }
            var date = day + "/" + month + "/" + year;
    
            return date;
        }; 
    
    0 讨论(0)
  • 2020-12-11 09:17

    The date object has functions for getting access to the individual date components. You can use:

    $('#vigencia_receta_11').val((nd.getMonth() + 1) + "/" + nd.getDate() + "/" + nd.getFullYear());
    

    Note that getMonth() returns a zero-indexed date, so you'll need to add 1 to get it to a human-readable date format.

    0 讨论(0)
提交回复
热议问题