The user profile page doesn't appear to allow the user to specify their timezone. How should we add this feature so the user can select and save their timezone and then have the web pages display the localised date?
Times are displaying in my browser according to the location of the server, so I edit a record at 7am local time, and it appears as if I edited it 4 hours in the future :)
Best solution for me is to allow the user to specify their timezone on their profile and then have this setting reflected in times displayed in the UI.
I'm set Clock.Provider to the UTC in file Startup.cs of ...Web.Host is OK
// using Abp.Timing;
public Startup(IHostingEnvironment env)
{
// Set Clock.Provider as UTC:
Clock.Provider = ClockProviders.Utc;
//_appConfiguration = env.GetAppConfiguration();
}
If Angular not sent date UTC you can using:
yourDate = abp.timing.convertToUserTimezone(yourDate); // to convert yourDate to date UTC.
You need to set the Clock.Provider to the UTC clock on the server. The documentation tells you that you need to set it but doesn't really tell you where. You just need to set this during the startup process. Here is a link to the docs that touch on it briefly.
Timing Documentation
Hope that helps.
Related
I am running a website in IIS on my local PC, I save a date as UTC and call .ToLocalTime() on it in the front end mvc website. If I run the website on my local PC it outputs the correct date and time adjusted for DST. If I run it in Azure in region UK West I get 1 hour behind. This hasn't been an issue until today i.e. the clocks changed on Saturday. Do I need to raise a ticket with Azure? Or am I doing it wrong?
Azure App server is using UTC time. If your site is not global just for UK. We can use the following code to get the UK local time.
DateTime utcNow = DateTime.UtcNow;
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"); //UK time zone
DateTimeOffset time = TimeZoneInfo.ConvertTimeFromUtc(utcNow, tz);
lab_time.Text = time.DateTime.ToString(CultureInfo.InvariantCulture); //display the datetime with label.
If your website is to be global that you may need to use javascrpt to do that, more detail please refer to another SO Thread.
Time-zone depends on the the server location literally.
I had faced the same issue. I had my server in Singapore and it used to clash with my zone, India.
It would affect the time and date formats too.
So, Better not use the ToLocalTime() at the server side. just get the UTC time from the server and convert to whatever local time at the client side. Issue resolved!
Hope this helps. Thank you.
I wrote a .NET program that creates live events in Youtube, but I cannot set the correct starting time and some settings like Keywords, and Region. This is what I do, when I create the Broadcast I put the starting Date and Time this way:
oLiveBroadcast.Snippet.ScheduledStartTime = String.Format(CDate(txtScheduledStart.Text), "yyyy-MM-ddTHH:mm:sszzzz")
...but the GMT is always referred to US (GMT -8). I think that the problem is in the receiving field .Snippet.ScheduledStartTime which has a dateTime format not including GMT. What can I do?
I also didn't find how and whare to set Region (in my case Itali IT-it) and searching Keywords
Thanks
In my project i saving the selected datetime(in UTC) from my datepicker.It saves the utc datetime only while application running in local.After deploying to azure it saves the selected datetime from datepicker irrespective of utc.
Update :
string selecteddate = "12/04/2016 05:30:15";
DateTime dt = Convert.ToDateTime(selecteddate).ToUniversalTime();
this code saves utc datetime in db in localhost,But it not working in azure
The DateTime instance you create with Convert.ToDateTime(selecteddate) will have DateTimeKind.Unspecified. Because of this, when you then call ToUniversalTime, it is making the assumption that the source value is in the local time zone of the computer where the code is running.
On Azure, that time zone is already UTC, so while the .Kind will change to DateTimeKind.Utc, the value will stay the same.
If you intended it to be converted from a particular time zone, then use TimeZoneInfo.ConvertTimeToUtc instead, passing a specific TimeZoneInfo value for the time zone you care about.
In general, don't rely on the local time zone setting in a web app, as the time zone could be different depending on where you deploy. Avoid ToUniversalTime and ToLocalTime, as well as DateTime.Now and other functions that depend on the local machine's time zone setting.
I'm trying to convert some dates that I have stored on the server (in UTC). I'd like to convert them to the user's time so it would be pretty for their time zone.
However, I'm not sure about how to go about doing that. What's the best practice to get the user's timezone from the request in the controller?
The timezone is not passed in the request headers. If you had the users time zone stored in a profile setting then you can easily format the date according to this but its not something you can just grab from the request. There are ways to do this in JavaScript.
I am struggling with setting up time zones with Trac. I have searched around but I have found nothing helpful. What can I do?
Both a whole site timezone or a per-user timezone settings would be helpful.
Like indicated by others, the solution is to add this to trac.ini:
[trac]
default_timezone = ...
But the tricky thing is the formatting (see http://trac.edgewall.org/ticket/9581):
you can either use GMT +xx:xx format (simple but not time saving aware)
or enter a timezone name e.g. America/Los_Angeles which requires pytz to be installed - see http://trac.edgewall.org/wiki/PyTz.
Default timezone for whole site is set up in the trac.ini:
[trac]
default_timezone = ...
In user preferences you have date time preferences («base_url»/prefs/datetime), where user can set his own (per user) timezone.
See for example http://trac.edgewall.org/prefs/localization
To set the site default timezone, edit trac.ini with the following syntax:
[trac]
default_timezone = GMT +10:00
or
[trac]
default_timezone = GMT -7:00