Jump to content
Vicarious

3.22: System Clock - Current Seconds

Recommended Posts

[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]

Link to comment
Share on other sites

@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 xD

 

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

Link to comment
Share on other sites

@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 xD

 

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

Link to comment
Share on other sites

Cheers, Freddy. :P

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.

Link to comment
Share on other sites

@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 xD

 

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...