TimeZoneInfo Class and Daylight saving time - windows-phone-7

I am trying to get the Timezone of the device (windows phone). I used this class and the property BaseUtcOffset. I live In Jordan, and it was suppose to give me +3 hours, but instead it gave me +2. i think its the daylight saving time, but i have no idea how to use it, any ideas?
var x = TimeZoneInfo.Local.BaseUtcOffset; // x.Hours = 2
the correct timezone from timeanddate.com

You should use GetUtcOffset().
The BaseUtcOffset property returns the difference between UTC and the time zone's standard time; the GetUtcOffset method returns the difference between UTC and the time zone's time at a particular point in time.

That's the right response. The timezone is 2 hours ahead of UTC. Local time is 3 hours ahead of UTC.
You might want to look at GetUtcOffset() or IsDaylightSavingsTime().

Related

Microsoft Flow for datetime between 2 times

I am looking to create a microsoft flow to check if an email was received between 18:00 and 18:15 Pacific Time. Ideally this would be a single formula instead of comparing time >= 18:00 and time <= 18:15
Currently I have:
convertTimeZone(triggerOutputs()?['body/receivedDateTime'], 'UTC', 'Pacific Standard Time', 'HH:mm')
to convert the datetime from UTC to PST in HH:mm format. My next thought was to subtract a time (18:00) from this and get the difference in minutes, then checking that this value is between 0 and 15
I've broken out my answer but you can do what you need with it. Personally, I think this is the most transparent and easiest approach but it's up to you.
Flow
To break it down ...
Firstly, the first step is me merely initialising a string that can be used to get the time from.
Next, I transform the minutes into an integer using the following expression (change out the locale as needed) ...
int(formatDateTime(parseDateTime(variables('Received DateTime'), 'en-AU', 'yyyy-MM-dd HH:mm'), 'HHmm'))
Finally, I do the comparison using this expression ...
and(greaterOrEquals(variables('Time Integer'), 1800), lessOrEquals(variables('Time Integer'), 1815))
Invalid
Valid

Measure elapsed time from fixed datetime

I am trying to measure how many minutes have elapsed from the time I turn my code from a fixed time, lets say 8:30 am of that day. If I turn my code on at 12am it should see that 210 minutes have elapsed. Any suggestions would help greatly. Thank you
You can import the datetime module, which has a class with the same name, with method datetime.datetime.now().
This returns an object representing the time when it is called.
This object has the method replace(), which can be used to 'change' the time to 8:30, if you call it like so - replace(hour=8, minute=30).
You can then create another similar object but without replacing the time, then you can simply subtract the first from the second to get the elapsed time as a datetime object.
This will then have elapsed_time.seconds to give you the time change in seconds, which can be divided by 60 if you want for the time in minutes.
Example
import datetime
time_A = datetime.datetime.now()
time_A = time_A.replace(hour=8, minute=30)
time_B = datetime.datetime.now()
elapsed_time = time_B - time_A
print(elapsed_time.seconds, "seconds have passed since 8:30 this morning")
If you wanted this for a specific timezone, you can add or subtract the offset from your current timezone. So if you are for example, 5 hours ahead of CST, you can have it get the difference from 3:30 instead.

Ruby - Get timezone offset from latitude and longitude for specific date and time

I am using the timezone gem to obtain the time zone from latitude and longitude. I need the time zone for some solar calculations. The API I use requires the timezone offset (without the daylight). For example now (2021/10/12 12:37) in UK with BST time the timezone offset for the API would be zero. With timezone though I would get 3600
tz = Timezone.lookup(51.51, 0.1)
=> #<Timezone::Zone name: "Europe/London">
tz.utc_offset
=> 3600
That's easy. I can check for daylight saving and correct.
(tz.dst?) ? (tz.utc_offset) : (tz.utc_offset - 3600)
I can do the same for another time (I do all the calculations in 2010) as long as it is in my locale timezone.
If I try, say, Melbourne, I am not able to create a time in that location and check the daylight saving. I am sure I am doing something wrong. Am I overthinking it?
For example:
tz = Timezone.lookup(-37.814, 145)
=> #<Timezone::Zone name: "Australia/Melbourne">
tz.utc_offset
=> 39600 ((10 + 1)h)
This is now (2021/10/12 12:37), but for my API to work this should be 10 because daylight should not be included.
My idea was to take a reference time, 2010/01/01 01:00 and make all the calculations for that time. The problem is that I don't know how I can create a time in a specific time zone and check whether that time is a daylight time.
I have tried
reftime = tz.time(Time.new(2010,1,1,1,0))
but if do
reftime = tz.time(Time.new(2010,1,1,1,0))
reftime.dst?
I get false, but it should be true.
How can I check whether a specific date in a specific location is in daylight saving mode?
Melbourne has started daylight saving at 2021-10-03 03:00:00. So it's using AEDT but not AEST.

Google Spreadsheet time between date - hour calculation

I am at a loss, i looked around the internet and stackoverflow but every so called solution is giving either errors or plainly don't work.
I have the following setup.
4 fields (setup in date dd-mm-yyyy, hour hh:mm:ss) seconds are not important.
start date : 7-1-2020
start hour : 23:30:00
end date : 8-1-2020
end hour : 03:50:00
What i want to happen is to calculate the diffrence in 'hours, minutes' between the end and the start date, hour. But when I calculate and change the end date to lets say 09-01-2020 it does not count the extra 24h at all.
Use Text format:
=text(A3-A1+A4-A2,"[H]:MM")
You need to format the time difference as a duration using the custom format
[h]:mm
for hours and minutes
or
[h]
for whole hours.
There are some good notes on how it works in Excel here and as far as I can tell from testing it Google Sheets is the same.
Alternatively, if I read your question as wanting to drop the minutes and seconds from the times before doing the calculation, you could use
=(B3-B1)*24+hour(B4)-hour(B2)
and just format the result as a normal number.
After alot of fiddeling and this post i came to the conclusion that the main issue was not laying within the mathematical but within the format of the cell.
By default all time values in sheets are 24h max.
So the basic formula =start - end
The time format needed should be
more date time format
elapsed hours : elapsed minutes
apply
Now you should see the correct elapsed hours and minutes

How to get latest updated record from sys_user table which is modified at or after certain time stamp in ServiceNow

I want to fetch record from the sys_user table which is updated at or after certain time stamp.
for that I have created rest request as
https:/service-now.com/api/now/v1//table/sys_user?sysparm_query=sys_updated_on>=javascript:gs.dateGenerate('2017-10-30','01:25:00')
I had converted current time which is in IST format into GMT and pass it to dateGenerate() function.
Problem statement -
I don't want to convert the IST to GMT, is there any way by which i can identify ServiceNow instance time zone at runtime and convert given time into that time stamp and get the users.
If i can pass this date and time in UTC format.
Ahoy!
This is a great question, and something that's quite difficult in ServiceNow (dealing with time-zones).
As such, I've written a tool to manage this for you. It's totally free!
The tool is called TimeZoneUtil, and can be found here:
https://snprotips.com/blog/2017/9/12/handling-timezones-in-servicenow-timezoneutil
You simply need to initialize a GlideDateTime object, set its' time-zone to IST, use setDisplayValue() to set its' time based on IST current time, then use .getValue() to get that same time in system time.
This is because getDisplayValue()/setDisplayValue() work based on time-zone, whereas setValue()/getValue() always return the corresponding system time.
EDIT: In order to make this a little more clear, I'll provide some example usage below.
var tz = new TimeZoneUtils(); //initialize with current time
gs.print(tz.getOffsetHours()); //prints out "-7" in my instance, as the system time is in Pacific.
tz.setTimeZone('Asia/Kolkata'); //sets the time-zone to IST/UTC+5.5
gs.print(tz.getOffsetHours()); //prints "5.5".
gs.print(tz.getGDT().getDisplayValue()); //Prints the current time in IST (2017-11-01 20:52:31 at the moment).
gs.print(tz.getGDT().getValue()); //Prints the current time in system time (2017-11-01 15:23:12 at present).
gs.print(new TimeZoneUtils().setTimeZone('Asia/Kolkata').getDisplayValue()); //Single line, also prints current time in IST: 2017-11-01 20:52:31
The first 6 lines there, demonstrate basic usage and explain how it works.
The eighth line however, demonstrates usage on a single line, which you can use inside a query string. For example:
sysparm_query=sys_updated_on>=javascript:new TimeZoneUtils().setTimeZone('Asia/Kolkata').getDisplayValue()
Hope this helps!
Tim Woodruff
Author, Learning ServiceNow & Building Powerful Workflows
Owner/Founder, SN Pro Tips

Resources