I have the following dataweave expression that displays the time and date that is 90 days before today's date in my local timezone (IST), I want to get the timezone as GMT+00:00 instead of GMT+05:30
my dataweave expression:
%dw 2.0 var time= now() output application/json
---
{
"date" : time - ("P$(90)D" as Period)
}
current output:
{
"date": "2020-11-12T09:14:15.908+05:30"
}
desired output
{
"date": "2020-11-12T09:14:15.908+00:00"
}
there are so many ways to show the timeZone , I let you know one example that I have tried for you
your input was now()
%dw 2.0
var time= now()
output application/json
---
{
"date": (now() >> 'UTC') as DateTime {format: "dd-MMM-yy hh.mm.ss.SSSSSSSSS a VV"} as String {format: "yyyy-MM-dd'T'HH:mm:ss:SSS Z"}
}
the output of this code is:
{
"date": "2021-02-10T07:09:11:815 +0000"
}
Note: There is no time difference between Greenwich Mean Time (GMT) and Coordinated Universal Time (UTC)
This code you can easily modify according to your requirement for example if you want the same code for GMT +5:30 that is Asia/Calcutta time Zone ID
that will be as below
%dw 2.0
var time= now()
output application/json
---
{
"date": (now() >> 'Asia/Calcutta') as DateTime {format: "dd-MMM-yy hh.mm.ss.SSSSSSSSS a VV"} as String {format: "yyyy-MM-dd'T'HH:mm:ss:SSS Z"}
}
so main point is here that you need to specify the time zone ID to get that in your output
and this is the official document link that shows a list of all Time Zone ID's in mulesoft at the present day (10-02-2021)- https://docs.mulesoft.com/mule-runtime/4.3/dataweave-cookbook-change-time-zone
Thanks
Related
Using flatpickr, I allow the user to specify the time and date of a future meeting that includes their time zone.
The result is the following value:
Mon May 25 2020 12:00:00 GMT-0600 (Mountain Daylight Time)
They can choose a team member to meet with and that time member will have set their current time zone and I'm storing that value using ActiveSupport::TimeZone (https://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html)
I am trying to figure out how to take the date result above and display to the user who is scheduling the meeting, "It will be 7pm for X."
I send the attendeeZone and meetingTime to a Rails endpoint:
def time_for_attendee
attendeeZone = params["attendeeZone"]
# => "Tokyo"
meetingTime = params["meetingTime"]
# => "Mon May 25 2020 12:00:00 GMT-0600 (Mountain Daylight Time)"
attendeeTime = ???
render json: {
attendeeZone: attendeeZone,
meetingTime: meetingTime,
attendeeTime: attendeeTime
}
end
How would I convert that meetingTime to the attendeeTime based on their time zone?
I got close with Time.zone.now.in_time_zone(attendeeZone) but I'm not sure how to convert the format of meetingTime to replace now.
It's .parse()
Time.zone.parse(params["meetingTime"]).in_time_zone(attendeeZone)
Alternatively, if you assign it to a model, then it will be parsed automatically already.
Can I change the time zone in the result from Alpha Vantage API? Here is an example of the output. It's currently in EST. I'd like to get it in IST.
'Meta Data': {
'1. Information': 'Intraday (1min) open, high, low, close prices and volume',
'2. Symbol': 'BSE:------',
'3. Last Refreshed': '2019-11-01',
'4. Output Size': 'Compact',
'5. Time Zone': 'US/Eastern
}
'Time Series (1min)': {
'2019-11-01 00:08:59': {
'1. open': '70.7500',
'2. high': '70.7500',
'3. low': '70.7500',
'4. close': '70.7500',
'5. volume': '0'
},
Welcome to StackOverflow!
Right now the time zone that is returned is the only time zone you will receive from the API. However, if you're pulling the data in with a python script. You can always convert it to your time zone of choice.
from alpha_vantage.timeseries import TimeSeries
from datetime import datetime
import pytz
ts = TimeSeries()
data, meta_data = ts.get_daily('TSLA')
format = '%Y-%m-%d %H:%M:%S'
datetime = datetime.strptime(meta_data['3. Last Refreshed'], format)
old_timezone = pytz.timezone(meta_data['5. Time Zone'])
new_timezone = pytz.timezone("Asia/Calcutta")
# returns datetime in the new timezone
my_timestamp_in_new_timezone = old_timezone.localize(datetime).astimezone(new_timezone)
print(my_timestamp_in_new_timezone.strftime(format))
You could run a method that just converts all the times to whatever timezone you want when you pull the data
ts.get_daily('TSLA') should be changed to ts.get_intraday('TSLA').
I would like to either get the datetime of when the message was sent in user's local timezone or his/her local timezone.
How can I get that from in my bot? facebook gives the timestamp but I doubt if that timestamp is calculated based on the local timezone of the user.
The documentation gives this example:
{
"sender":{
"id":"USER_ID"
},
"recipient":{
"id":"PAGE_ID"
},
"timestamp":1458692752478,
"message":{
"mid":"mid.1457764197618:41d102a3e1ae206a38",
"text":"hello, world!",
"quick_reply": {
"payload": "DEVELOPER_DEFINED_PAYLOAD"
}
}
}
The timestamp field in this example is a Unix timestamp in terms of milliseconds. Unix timestamps are always in terms of Coordinated Universal Time (UTC). In other words, the epoch reference point is January 1st, 1970, 00:00:00.000 UTC.
Therefore, time zones are irrelevant to the message body. You should simply convert from UTC to the desired time zone (probably the user's local time zone) when the message is displayed.
I am getting some results from a weather API and one of that is date in epoch time stamp.
I found that converting with Date(timeIntervalSince1970:) I get the right date
I am using the specific number --> 1501452000 and I get 2 results on Playground
1) Jul 31,2017,12:00AM. -- when --> let date = Date(timeIntervalSince1970: 1501452000)
2) 2017-07-30 22:00:00 +0000 when --> print(date)
API results are :
"time_epoch": 1501452000,
"time": "2017-07-30 23:00",
By checking the rest of my results they are matching with the rest of the API results....... but when I convert 1501452000 -> to date I don't get the correct Hour 23:00 but 22:00 !
Any idea what is happening ?
is it wrong the API( I don't think so ) or the way I am converting it?
Thanks a lot
The timeIntervalSince1970 initializer sets up the time in the UTC timezone, while your API might be sending dates in GMT. When you are using print(data), you have different results, because if you are not using a DateFormatter to generate the String format of the Date object, it uses your devices current settings when formatting the Date object.
A Date object represents an absolute point in time, but when you are printing it with a DateFormatter, it gets converted into a location/time zone specific, relative representation. You just have to set up your DateFormatter to match the time zone settings of your API and you will see the dates correctly printed.
This issue happens on daylight saving times. Is your country changing daylight saving on this exact date?
let date = Date(timeIntervalSince1970: 1501452000) in Playgrounds should give you the time in your system's timezone when you see it on the right hand side.
When you print it and see 2017-07-30 22:00:00 +0000- this is the same timestamp in GMT
Is the API showing a particular time zone? It looks like GMT+1
In my client application I have the Latitude & longitude information from skyhook API based on its I.P.
Now based on the latitude and longitude information I need to find out the timezone information of the client. But in the google timezone API documentation https://developers.google.com/maps/documentation/timezone/ I see that timestamp is a mandatory field. In which case what should I need to do.
Also can you kindly help me understand what does the timestamp corresponds to? For e.g :- If my Application server is in U.S.A (say PST timezone) and it makes the google API call passing the server timestamp.
If user logs into client application from India passing lat / long information, to the app server to get the timezone information what will the API provide as dstOffset and rawOffset? i.e If I add the server timestamp with dstOffset and rawOffset will I be getting the client machine timezone information?
I've been scratching my head on Google's Timezone API for a few minutes, specifically on the timestamp parameter. Maybe this will lay out the need:
In San Diego, we (now, in August) have a GMT offset of -8 because of daylight savings time. However, in November we'll have a GMT offset of -7.
So which gmt offset should Google return? -7 or -8? They're both valid, but it depends on what day you take the measurement.
Enter the Timestamp argument. Running the service now, and using a timestamp value of August 2015, I get this response:
{
"dstOffset" : 3600,
"rawOffset" : -28800,
"status" : "OK",
"timeZoneId" : "America/Los_Angeles",
"timeZoneName" : "Pacific Daylight Time"
}
But if I bump the timestamp to November 2015 (once San Diego is out of daylight savings, I end up with this):
{
"dstOffset" : 0,
"rawOffset" : -28800,
"status" : "OK",
"timeZoneId" : "America/Los_Angeles",
"timeZoneName" : "Pacific Standard Time"
}
In both cases the rawOffset is the same, but the DST changed because of the timestamp I provided. If you just want to know the raw timezone, the timestamp doesn't matter.
But if you want an application to reliably do something at 8:00am in San Diego in August and 8:00am in November in San Diego, you'll need to engage the timestamp.
Putting it another way, what's the value of knowing that San Diego is normally -7 hours offset from GMT. If you're working with timezones, you're likely trying to ensure that your UTC time is matched up with what a real person in that location is experiencing. As such, the DST offset is critical.
The documentation link you provided clearly states that the timestamp should be in UTC and that it is used to show the correct DST offset value. It will also control if the timeZoneName field is shown with "Standard" or "Daylight" in the name.
If you don't care about that and just want the timeZoneId field, then it doesn't matter what value you pass.
Try this
DateDiff("s", "1/1/1970", DateTime.Now)