Vicarious Posted June 20, 2012 Share Posted June 20, 2012 I know this isn't a complicated idea but I can't find it anywhere I look. I just need a function that returns the current seconds on the system clock. Any help would be greatly appreciated, thank you! ~V Quote Link to comment Share on other sites More sharing options...
Janilabo Posted June 20, 2012 Share Posted June 20, 2012 [scar]function Seconds: Integer; var tmp: string; l: Integer; begin tmp := TimeToStr(Time); l := Length(tmp); Result := StrToInt(Copy(tmp, (l - 1), 2)); end; begin WriteLn(Seconds); end.[/scar] Quote Link to comment Share on other sites More sharing options...
shadowrecon Posted June 20, 2012 Share Posted June 20, 2012 [scar]function Seconds: Integer;var tmp: string; l: Integer; begin tmp := TimeToStr(Time); l := Length(tmp); Result := StrToInt(Copy(tmp, (l - 1), 2)); end; begin WriteLn(Seconds); end.[/scar] I tried this example and it returned -1. Debugged it and it was only debugging 'AM'. Heres janilabo's example fixed. [scar] function Seconds: Integer; var tmp: string; l: Integer; begin tmp := TimeToStr(Time); l := Length(tmp); Result := StrToInt(Copy(tmp, (l - 4), 2)); end; begin WriteLn(Seconds); end. [/scar] I wrote this example which converts the time to seconds. [scar] program New; function Seconds: Integer; var tmp, Hours, Mins, Secs: string; begin tmp := TimeToStr(Time); tmp := GetNumbers(tmp); Hours := Copy(tmp, 1, 2); Mins := Copy(tmp, 3, 2); Secs := Copy(tmp, 5, 2); Result := ((StrToIntDef(Hours, -1) * 60) * 60) + (StrToIntDef(Mins, -1) * 60) + StrToIntDef(Secs, -1); end; begin WriteLn(Seconds); end. [/scar] Quote Link to comment Share on other sites More sharing options...
FHannes Posted June 20, 2012 Share Posted June 20, 2012 @shadowrecon: Janilabo's code isn't wrong, it's localized, and so is yours. Each computer uses a localized timestamp format. In the us this uses a 12 hour format, including AM or PM at the end of the timestamp. In Europe, most countries use the 24 hour format, which is why Janilabo's example didn't work for you. I don't get why people keep overcomplicating this Try this: [scar]function Seconds: Byte; var Str: string; begin DateTimeToString(Str, 's', Now); Result := StrToInt(Str); end; begin WriteLn(Seconds); end.[/scar] @OP: You shouldn't be using a version as outdated as SCAR 3.22, download the latest version here: http://www.scar-divi.com/?page=download Quote Link to comment Share on other sites More sharing options...
Vicarious Posted June 20, 2012 Author Share Posted June 20, 2012 @shadowrecon: Janilabo's code isn't wrong, it's localized, and so is yours. Each computer uses a localized timestamp format. In the us this uses a 12 hour format, including AM or PM at the end of the timestamp. In Europe, most countries use the 24 hour format, which is why Janilabo's example didn't work for you. I don't get why people keep overcomplicating this Try this: [scar]function Seconds: Byte; var Str: string; begin DateTimeToString(Str, 's', Now); Result := StrToInt(Str); end; begin WriteLn(Seconds); end.[/scar] @OP: You shouldn't be using a version as outdated as SCAR 3.22, download the latest version here: http://www.scar-divi.com/?page=download This works perfectly thanks very much for the help. Haven't had a need for scar since then, I have to say Scar Divi has come on leaps and bounds since then ~V Quote Link to comment Share on other sites More sharing options...
Janilabo Posted June 20, 2012 Share Posted June 20, 2012 Cheers, Freddy. Didn't even remember there was DateTimeToString function in SCAR.. Thanks. @Vicarious, yeah, I agree (about improved SCAR Divi), Freddy has been doing a really great job with the project. BTW, check out the CHANGELOG of SCAR Divi. ..you will notice just how many improvements, additionts, bug fixes there has been since 3.22 version.. I can tell, you'll be amazed! It shows all the additions, bug fixes, improvements and deletions since 3.25 version, though. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted June 20, 2012 Share Posted June 20, 2012 @shadowrecon: Janilabo's code isn't wrong, it's localized, and so is yours. Each computer uses a localized timestamp format. In the us this uses a 12 hour format, including AM or PM at the end of the timestamp. In Europe, most countries use the 24 hour format, which is why Janilabo's example didn't work for you. I don't get why people keep overcomplicating this Try this: [scar]function Seconds: Byte; var Str: string; begin DateTimeToString(Str, 's', Now); Result := StrToInt(Str); end; begin WriteLn(Seconds); end.[/scar] @OP: You shouldn't be using a version as outdated as SCAR 3.22, download the latest version here: http://www.scar-divi.com/?page=download The metric system, and now this? This is Sparta! @Freddy: Will this DateTimeToString function work on both the formats. 12hr, and 24hr? Quote Link to comment Share on other sites More sharing options...
FHannes Posted June 20, 2012 Share Posted June 20, 2012 The metric system, and now this? This is Sparta! @Freddy: Will this DateTimeToString function work on both the formats. 12hr, and 24hr? Yes, it formats the timestamp according to a format which you specify, where as the other methods use a system default format. You can find more information about the formating here: http://www.delphibasics.co.uk/RTL.asp?Name=DateTimeToString Quote Link to comment Share on other sites More sharing options...