We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Time Conversion
- Discussions
Time Conversion
Time Conversion
Sort by
recency
|
286 Discussions
|
Please Login in order to post a comment
Java
C#
!/bin/python3
def timeConversion(z): # Write your code here h=0 s=z[:-2] a=s.split(":") if("PM" in z): b=int(a[0]) if(b>=1 and b!=12): h=b+12 print(h,end="") else: print(a[0],end="") if("AM" in z): c=int(a[0]) if(c==12): h=0 print(0,end="") print(h,end="") else: print(a[0],end="") print(":"+a[1],end="") print(":"+a[2])
z = input() timeConversion(z)
**Code in Python ** def timeConversion(s): h=s[:2] se=s[-2:] rest=s[2:-2] ho=int(h) if se=='AM': if ho==12: ho=0 else: if ho != 12: ho += 12 return f"{ho:02}{rest}"
define TWELVE_ASCII 99 // "1" + "2" = 49+50 = 99
define ZERO_ASCII 48
void ConvertToMilitarTime(string am_pm, string& hours) { uint8_t digit_sum = hours[0] + hours[1]; if(am_pm == "AM") { if(digit_sum < TWELVE_ASCII) { hours[0] = hours[0] + 1; hours[1] = hours[1] + 2; } else if(digit_sum == TWELVE_ASCII) { hours[0] = ZERO_ASCII; hours[1] = ZERO_ASCII; } } else // is PM { if(digit_sum != TWELVE_ASCII) { hours[0] = hours[0] + 1; hours[1] = hours[1] + 2; } } } /* * Complete the 'timeConversion' function below. * * The function is expected to return a STRING. * The function accepts STRING s as parameter. */
string timeConversion(string s) { string am_pm(s, 8); string min_sec(s, 2, 6); string hours_digits(s, 0, 2);
}