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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Warmup
  4. Time Conversion
  5. Discussions

Time Conversion

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 4575 Discussions, By:

recency

Please Login in order to post a comment

  • alban_tyrex
    39 minutes ago+ 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/G7bia__Vxqg I'll be happy to hear back from you

    #include <bits/stdc++.h>
    
    using namespace std;
    
    
    // morning h == 12 = > 0
    // evening h != 12 => h +=12
    
    int main() {
        string s;
        cin >> s;
        int h;
        sscanf(s.c_str(), "%d", &h);
        if(s[8] == 'A' && h == 12) h = 0;
        if(s[8] == 'P' && h != 12) h+=12;
        cout << setw(2) << setfill('0') << h;
        cout << s.substr(2, 6);
        return 0;
    }
    
    0|
    Permalink
  • sraa7877
    1 day ago+ 0 comments

    javascript

    let timeArray = s.split(':')
    let hr = Number(timeArray[0]);
    let mi = (timeArray[1]);
    let si = timeArray[2].split('')
    let sec = (si[0]+si[1]);
    let arr = []
    if(si[2]=='P' && si[3]=='M'){
     if(hr<12){
    hr = hr+12;
    }
    arr.push(String(hr).padStart(2, '0'))
    }else if(si[2]=='A' && si[3]=='M'){
     if(hr==12){
    arr.push("00")
    }else{
    arr.push(String(hr).padStart(2, '0'))
    }}
    

    ar r.push(mi) arr.push(sec) let ans = arr.join(":") return ans;

    0|
    Permalink
  • mustafaxv7
    2 days ago+ 0 comments

    Give me your opinions guys:

    def timeConversion(s):
        time_part = s.split(":")
        if "PM" in time_part[2]:
             time_part = s.split("PM")
             time_part_liste = time_part[0].split(":")
             if time_part_liste[0] == "12":
                s = (":").join(time_part_liste)
             else:
                 time_part_liste[0] = str(int(time_part_liste[0]) + 12)
                 s = (":").join(time_part_liste)
        elif "AM" in time_part[2]:
            time_part = s.split("AM")
            time_part_liste = time_part[0].split(":")
            if time_part_liste[0] == "12":
                time_part_liste[0] = "00"
                s = (":").join(time_part_liste)
            else:
                s = (":").join(time_part_liste)
        return s
    
    0|
    Permalink
  • aa_fireskull_f1
    3 days ago+ 0 comments

    hello can this also help for the female players time management i need some good programs for making a time and date of my players running in a ground for practice

    0|
    Permalink
  • aa_fireskull_f1
    3 days ago+ 0 comments

    hello can this also help for the female players time management i need some good programs for making a time and date of my players running in a ground for practice

    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy