0

I've date = 12/06/2017(mm/dd/yyyy) and time 02:11.

The code is as follows

 var date=$('#datepicker_reservation').val();// returns date

 var time=$('#timePicker_reservation').val();// returns time

Help ...Thanks in advance

1
  • You can concatenate the two strings with a space var datetime = date + ' ' + time; Commented Dec 28, 2017 at 12:29

2 Answers 2

1

You can try this:

var rdate = $('#datepicker_reservation').val().split('/');
var rtime = $('#timePicker_reservation').val();
var newdt = rdate[2]+'-'+rdate[0]+'-'+rdate[1]+' '+rtime;
Sign up to request clarification or add additional context in comments.

Comments

0

function fnclick()
{
 var date= "12-04-2017"

 var time=" 05:12 PM"
var date =  formatDate(new Date(date + time))
     $("#div1").html('').html(date);
     alert(date);
}

function formatDate(date) {
    try {
        var hours = date.getHours();
        var minutes = date.getMinutes();
        var ampm = hours >= 12 ? 'PM' : 'AM';
        hours = hours % 12;
        hours = hours ? hours : 12; // the hour '0' should be '12'
        minutes = minutes < 10 ? '0' + minutes : minutes;
        var strTime = hours + ':' + minutes + ' ' + ampm;
        return date.getMonth() + 1 + "-" + date.getDate() + "-" + date.getFullYear() + " " + strTime;
    } catch (e) {

    }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="div1">

</div>

<button onclick='fnclick()'> show me date</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.