jquery function to convert datetime, split date time “2010-10-18 10:06” to return “18/10/2010” and “10:06”

后端 未结 5 540
野的像风
野的像风 2020-12-19 06:42

Hi I was wondering if there is any jquery function around which can take this dateTime \"2010-10-18 10:06\" and convert and split it returning \"2010/10/18\" and \"10:06\".<

相关标签:
5条回答
  • 2020-12-19 06:49

    datejs. Check it, its cool and it does pretty good job for all the possibilities and error handling is also pretty good.

    0 讨论(0)
  • 2020-12-19 07:06

    Converting with DateJs should be as easy as:

    var d1 = Date.parse('2010-10-18, 10:06 AM');
    alert(d1.toString('dd/mm/yyyy HH:mm:ss GMT'));
    

    It's currently the best library around

    0 讨论(0)
  • 2020-12-19 07:06

    Without a any external jQuery plugin like DateJs. We can get the date as given below.

    var datetime= '2010-10-18 10:06 AM' // Default datetime will be like this.
    
    //By Spliting the input control value with space
    var date=datetime.split(' ')[0];
    //date -2010-10-18
    
    0 讨论(0)
  • 2020-12-19 07:12
    <input type="text" id="tbDateTime" value="2010-10-18 10:06" />
    <input type="text" id="tbDate" value="" />
    <input type="text" id="tbTime" value="" />
    
    <input type="button" id="btnSubmit" value="Submit" />
    
    
    <script type="text/javascript">
        $(function () {
            $('#btnSubmit').click(function () {
                var dateTimeSplit = $('#tbDateTime').val().split(' ');
    
                var dateSplit = dateTimeSplit[0].split('-');
                var currentDate = dateSplit[2] + '/' + dateSplit[1] + '/' + dateSplit[0];
                //currentDate is 18/10/2010
    
                $('#tbDate').val(currentDate);
    
                var currentTime = dateTimeSplit[1];
                //currentTime is 10:06
    
                $('#tbTime').val(currentTime);
            });
        });
    </script>
    
    0 讨论(0)
  • 2020-12-19 07:12

    Have a look Here

    It includes a function called fromString which would help you.

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