Mega Code Archive

 
Categories / Delphi / Forms
 

Easy Way for format 12hrs time to 24 hrs

Title: Easy Way for format 12hrs time to 24 hrs Question: How can i change my system time to 24 hrs format in all time? Answer: Send a valid datetime as a string to this func' it will return 24 hrs formattime as a string. Function Format24hrTime(StrTime:String):String; Var TempDateTime : TdateTime; H,M,S,Ms : Word; begin TempDateTime := StrToDateTime(StrTime); DEcodeTime(TempDateTime,H,M,S,Ms); If(Copy(Trim(StrTime),Length(StrTime)-1,2) = 'PM')Then BEgin H := 12 + H Mod 12; End Else If(Copy(Trim(StrTime),Length(StrTime)-1,2) = 'AM')Then Begin H:=H mod 12 End; StrTime :=DateToStr(Date)+' '+Inttostr(H)+TimeSeparator+Inttostr(M)+ TimeSeparator+Inttostr(S); Result := StrTime; end;