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.
- Prepare
- Algorithms
- Warmup
- Time Conversion
- Discussions
Time Conversion
Time Conversion
Sort by
recency
|
4882 Discussions
|
Please Login in order to post a comment
static String amToPm(Integer hour, String time) { String converser = String.format("%02d", hour); time = converser+ time.substring(2, time.length()-2); return time; }
C#
return (DateTime.Parse(s)).ToString("HH:mm:ss");
include
include
include
include
include
include
include
include
include
include
typedef struct clock{ int hrs; char ch1; int mm; char ch2; int ss; char AMPM[2]; }clock;
int main(){ clock ck ; scanf("%d%c%d%c%d%s",&ck.hrs,&ck.ch1,&ck.mm,&ck.ch2,&ck.ss,ck.AMPM); if(ck.hrs>12 || ck.mm>59 || ck.ss>59){ printf("Invalid\n"); exit(1); } if(strcmp(ck.AMPM,"AM")==1 && ck.hrs<12) ck.hrs = 12 + ck.hrs; else if(strcmp(ck.AMPM,"AM")==0 && ck.hrs==12) ck.hrs = 0;
if(ck.mm/10 == 0 && ck.ss/10 == 0 && (ck.hrs/10==0 || ck.hrs==0))printf("0%d%c0%d%c0%d",ck.hrs,ck.ch1,ck.mm,ck.ch2,ck.ss); else if(ck.mm/10==0 && (ck.hrs/10==0 || ck.hrs==0))printf("0%d%c0%d%c%d",ck.hrs,ck.ch1,ck.mm,ck.ch2,ck.ss); else if(ck.mm/10==0 && ck.ss/10==0)printf("%d%c0%d%c0%d",ck.hrs,ck.ch1,ck.mm,ck.ch2,ck.ss); else if(ck.ss/10==0 && (ck.hrs/10==0 || ck.hrs==0))printf("0%d%c%d%c0%d",ck.hrs,ck.ch1,ck.mm,ck.ch2,ck.ss); else if( ck.hrs/10==0 || ck.hrs==0)printf("0%d%c%d%c%d",ck.hrs,ck.ch1,ck.mm,ck.ch2,ck.ss); else if(ck.ss/10 == 0) printf("%d%c%d%c0%d",ck.hrs,ck.ch1,ck.mm,ck.ch2,ck.ss); else if(ck.mm/10 == 0) printf("%d%c0%d%c%d",ck.hrs,ck.ch1,ck.mm,ck.ch2,ck.ss);
else printf("%d%c%d%c%d",ck.hrs,ck.ch1,ck.mm,ck.ch2,ck.ss); }