Page 1 of 1

OffSet Time zone -Fail

Posted: 20 Aug 2014, 16:13
by joysprod
Is there an easy way using the Date & Time node, Covert to Text and an expression node to offset the system time by a number of hours? I just cant figure it!

Have been trying to create a series of clocks each showing a different time zone.

Regards

Peter

Re: OffSet Time zone -Fail

Posted: 20 Aug 2014, 16:29
by chriss0212
do you need just the time or the date also?

if just the time...you get everything you need out of the dateTime node...and just need to ad the offset...of course with a modulo function

greetz

christian

Re: OffSet Time zone -Fail

Posted: 21 Aug 2014, 08:36
by Daniel Willer
There are several DateTime Methods in .Net you can use inside a little Script or even an expression.
Check http://msdn.microsoft.com for further info.

D

Re: OffSet Time zone -Fail

Posted: 25 Aug 2014, 19:03
by joysprod
Hi Chris & Daniel

Thanks for that. Yes I have that working OK by taking the hours and minutes as separate items from the DateTime node and + or - the hours with the modulo working fine.

What I was trying to do, is what Daniel mentioned in the next post buy using an expression and DateTime AddHours. I can see loads of examples that would work in a script but cant get it working inside an expression. Just cant get the syntax right to allow it to compile correctly. Ventuz Help in this case is No Help as no examples.

Regards

Peter

Re: OffSet Time zone -Fail

Posted: 25 Aug 2014, 19:12
by Chris
quick example, you just need to add the string outputs to the script. (i.e 'istHour' etc)
you can use any local system time zones.

chris

Code: Select all

	DateTime dt = DateTime.Now;
		
		
 		var ist = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt, TimeZoneInfo.Local.Id, "India Standard Time");
		istHour = ist.Hour.ToString();
		
		var pt = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt, TimeZoneInfo.Local.Id, "Pacific Standard Time");
		ptHour = pt.Hour.ToString();
		
		var ct = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt, TimeZoneInfo.Local.Id, "Central Standard Time");
		ctHour = ct.Hour.ToString();
		

Re: OffSet Time zone -Fail

Posted: 25 Aug 2014, 19:15
by Chris
forgot to mention this just gives you the hours as an output not min and secs but thats all your after i guess ;)

chris

Re: OffSet Time zone -Fail

Posted: 26 Aug 2014, 08:49
by Daniel Willer
It is a little tricky to do it in a expression.
Because the expression nodes does not have the type DateTime you have to parse the value inside the expression to DateTime, add the hours and convert back to a string.
Just take a string expresion node and add the follwoing expression

Code: Select all

DateTime.Parse(A, System.Globalization.CultureInfo.InvariantCulture).AddHours(2).ToString("hh")

Re: OffSet Time zone -Fail

Posted: 26 Aug 2014, 14:59
by joysprod
Thank you both for most elegant solutions.

Daniel, each time I encounter such a concise and beautiful solution I know I have so many things to learn in Ventuz.

Regards

Peter

Re: OffSet Time zone -Fail

Posted: 27 Aug 2014, 10:02
by Chris
Agreed ;)