convert 12-hour hh:mm AM/PM to 24-hour hh:mm
Try this
var time = $("#starttime").val();
var hours = Number(time.match(/^(\d+)/)[1]);
var minutes = Number(time.match(/:(\d+)/)[1]);
var AMPM = time.match(/\s(.*)$/)[1];
if(AMPM == "PM" && hours<12) hours = hours+12;
if(AMPM == "AM" && hours==12) hours = hours-12;
var sHours = hours.toString();
var sMinutes = minutes.toString();
if(hours<10) sHours = "0" + sHours;
if(minutes<10) sMinutes = "0" + sMinutes;
alert(sHours + ":" + sMinutes);
Convert AM/PM time to 24 hours format in C#?
From the specs:
"hh" The hour, using a 12-hour clock from 01 to 12.
"HH" The hour, using a 24-hour clock from 00 to 23.
So use HH.
How to convert HH:MM:SS AM/PM to 24 hour format in R?
May be we can use format
time <- format(strptime(c("1:00:29 AM","1:00:29 PM"), "%I:%M:%S %p"), "%H:%M:%S")
time
#[1] "01:00:29" "13:00:29"
This can be converted to times
class using ?times
from chron
library(chron)
times(time)
#[1] 01:00:29 13:00:29
Converting XX:XX AM/PM to 24 Hour Clock
Try
String time = "3:30 PM";
SimpleDateFormat date12Format = new SimpleDateFormat("hh:mm a");
SimpleDateFormat date24Format = new SimpleDateFormat("HH:mm");
System.out.println(date24Format.format(date12Format.parse(time)));
output:
15:30
How to convert a/p (am/pm) time value in python to 24hr format
Add an 'm'
to the string you input to strptime
and put the %p
in its second argument,
>>> from datetime import datetime
>>> time_value = '3:50a'
>>> datetime.strptime(str(time_value)+'m', '%I:%M%p').strftime('%H:%M')
'03:50'
>>> time_value = '4:25p'
>>> datetime.strptime(str(time_value)+'m', '%I:%M%p').strftime('%H:%M')
'16:25'
How to convert AM/PM timestmap into 24hs format in Python?
Try this :)
Code:
currenttime = datetime.datetime.now().time().strftime("%H:%M")
if currenttime >= "10:00" and currenttime <= "13:00":
if m2 >= "10:00" and m2 >= "12:00":
m2 = ("""%s%s""" % (m2, " AM"))
else:
m2 = ("""%s%s""" % (m2, " PM"))
else:
m2 = ("""%s%s""" % (m2, " PM"))
m2 = datetime.datetime.strptime(m2, '%I:%M %p')
m2 = m2.strftime("%H:%M %p")
m2 = m2[:-3]
print m2
Output:
13:35
Related Topics
PDF Compression with Itextsharp
C# Random Numbers Aren't Being "Random"
Install to Same Path When Upgrading Application
How to Download a Nuget Package Without Nuget.Exe or Visual Studio Extension
Unit Testing ASP.NET MVC Authorize Attribute to Verify Redirect to Login Page
Dependency Injection VS Service Location
Why Do Some C# Lambda Expressions Compile to Static Methods
C# Winforms: How to Set Main Function Stathreadattribute
Curiously Recurring Template Pattern and Generics Constraints (C#)
Configureawait Pushes the Continuation to a Pool Thread
Uploading Files Not Working - Need Assistance
What Are the Differences Between Various Threading Synchronization Options in C#
Differencebetween Ienumerator and Ienumerable
Deciding on When to Use Xmldocument VS Xmlreader
Having the Output of a Console Application in Visual Studio Instead of the Console