mimoralea
mimoralea

Reputation: 9986

Is there a way to print a calculated time format string in C#?

I know the title might be confusing, but I'm not sure how to word it better....

I'm doing this to get the logs of the current hour:

'TraceSink-'yyyy-MM-dd HH'-Hourly.log'

How can I get the previous hour? i.e.:

'TraceSink-'yyyy-MM-dd (HH-1)'-Hourly.log'

Is there anything possible with time format like that?

EDIT: I don't have access to the C# code but a exe.config where I can change what goes inside.

Like var on DateTime.ToString(var);

Am I asking too much?

Upvotes: 2

Views: 311

Answers (3)

svenv
svenv

Reputation: 323

I don't know why you have this requirement, but I suspect that you may be receiving DateTime objects from a machine in another time zone... it could be helpful if you included the offset from UTC in your format string:

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx#zSpecifier

This way, when you see the log you can tell that the specific event occurred at UTC -3 hours.

I think that's the best you can do without access to the original code.

Upvotes: 0

comecme
comecme

Reputation: 6386

The answer to your question is no.

The format string only defines the format. It does not have the ability to perform calculation on it (and why would it?)

Upvotes: 3

John Saunders
John Saunders

Reputation: 161791

Subtract one hour from the date/time and format that.

Upvotes: 8

Related Questions