locked
how to show date time RRS feed

  • Question

  • User-1634604574 posted

    i want to show current date and time by this format

    2020/02/12 12:01:03

    Sunday, March 15, 2020 4:24 PM

Answers

  • User1535942433 posted

    Hi zhyanadil.it@gmail.com,

    Accroding to your description,I suggest you could use Date to set the format of yy/mm/dd hh:mm:ss and you could use Number to set zero before the value<10.

    More details,you could refer to below codes:

    <script src="Scripts/jquery-3.1.1.min.js"></script>
        <script>
            $(function () {
                Number.prototype.padLeft = function (base, chr) {
                    var len = (String(base || 10).length - String(this).length) + 1;
                    return len > 0 ? new Array(len).join(chr || '0') + this : this;
                }
                $("#Button1").click(function () {
                    event.preventDefault();
                    var d = new Date,
                        dformat = [d.getFullYear(),
                        (d.getMonth() + 1).padLeft(),
                        d.getDate().padLeft()].join('/') + ' ' +
                            [d.getHours().padLeft(),
                            d.getMinutes().padLeft(),
                            d.getSeconds().padLeft()].join(':');
                    $('#result').html(dformat);
                })
    
            })
        </script>
    
    
     <div id="result">
            </div>
            <asp:Button ID="Button1" runat="server" Text="Button" />

    Result:

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 16, 2020 1:34 AM