Eclipse:
DateFormat formatter = new SimpleDateFormat("hh:mm");
String formatstart_time=json_data.getString("start_time");
String formatend_time=json_data.getString("end_time");
try {
Time startValue = new Time(formatter.parse(formatstart_time).getTime());
Time endValue = new Time(formatter.parse(formatend_time).getTime());
user.setStartTime(startValue);//error
user.setEndTime(endValue);//error
//if string contains su and myday is sunday bla bla
user.setDay(parseDay(json_data.getString("day")));
mysched.add(user);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PHP:
$sql = "SELECT course_id, sections_id, rooms_id, start_time, end_time, day, studsched.schedule_id from schedule_tbl as sched,student_schedule_tbl as studsched where sched.schedule_id=studsched.schedule_id and student_id='$id' GROUP BY course_id, sections_id,sched_status='active';";
$result = mysqli_query($dbc, $sql);
while($row = mysqli_fetch_assoc($result)){
$json_output[] = $row;
}
echo json_encode($json_output);
I have my time in my table, the column is start_time and end_time.
Sample table column data:
start_time=11:30:00
end_time=16:00:00.
I am doing the query in my php, and then im getting the values through web service in eclipse. I want the data as (based from above) 11:30 AM - 4:00 PM, the military time will be converted to standard time and then without the second. Can you help me convert it using DateFormat formatter?
You parse the date with DateTime::createFromFormat
and then format it according to your needs… just like you'd do with any other date as well:
$start_time = "11:30:00";
$end_time = "16:00:00";
$start = DateTimeImmutable::createFromFormat("H:i:s", $start_time);
$end = DateTimeImmutable::createFromFormat("H:i:s", $end_time);
echo $start->format("g:i A") . " - " . $end->format("g:i A"), PHP_EOL;
This will print
11:30 AM - 4:00 PM
Please refer to the available formatting options at http://php.net/date