Commit b57f1d23 authored by Deep Dey's avatar Deep Dey

feat: add a test file for date picker

parent 432b8c71
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Datetime Picker</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<input type="date" id="datePicker">
<input type="time" id="timePicker">
<button id="logDatetime">Log Datetime</button>
<div id="result"></div>
<script>
function formatAMPM(date) {
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 strTime;
}
$(document).ready(function() {
$('#logDatetime').click(function() {
var date = $('#datePicker').val();
var time = $('#timePicker').val();
if (!date || !time) {
alert('Please select both date and time.');
return;
}
var selectedDateTime = new Date(date + 'T' + time);
var formattedDateTime = date + 'T' + formatAMPM(selectedDateTime);
//TODO: send date and formatAMPM(selectedDateTime) to the backend
$('#result').text(formatAMPM(selectedDateTime));
console.log(formattedDateTime);
});
});
</script>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment