In my MVC application I am selecting the company & doing my operations based on that.
as you can see in the Image below::
Here the problem is with the Timezone based on the company I have selected. Because I have to Insert the Datetime for the current Timezone.
We know in C# there are Inbuild properties like ::
DateTime.Now
DateTime.UtcNow
TimeZone.CurrentTimeZone
I just want the time based on companies selected from the above Dropdown in C#.
Please Help me on this,
Thanks in Advance.
You can get it by using Date.getTimezoneOffset(). This links might helps you.
http://aspdotnet-naresh.blogspot.in/2013/05/aspnet-how-to-convert-to-different-time.html
get client machine timezone in asp.net mvc
http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp
Get the default timezone for a country (via CultureInfo)
To start, I recommend http://nodatime.org, because they have some mapping functions from the more common Olson-format to the windows time zone format. Read more about this: Olson Time Zone Id to Windows Standard Format using Noda Time
To solve your problem, there are multiple options:
Save the name of the timezon in Olson format in your database.
Save the geolocation in your database. You can use the shape file with timezones to select the right timezone based on geolocations. http://efele.net/maps/tz/world/. There is also library to read this file: http://www.easygisdotnet.com/api/
Related
My Server has different time zone and I want to access my website from different timezone. So I want to display time in website according to system from which I will open website not want to set time according to server timezone.
Is there any way to solve my problem?
Please help me.
Thanks in Advance.
You can use javascript for same.
Add below code in your html (design) page
var currentdate = new Date()
This will give you current Date-time at end users machine.
var offset = currentdate .getTimezoneOffset()
This will give you current time zone offset with actual GMT time.
Using this value you can also identify the End-users time zone.
I have an application which I developed in the UK. I have now deployed this to a US server and the dates are incorrect. I have a date time picker which I have set the format to be dd/mm/yyyy, when I select the date time picker I notice that when I inspect the element the date is actually 12/10/2013.
When I store this to the database this is being transformed as 2013-12-10 and then when I retrieve this from the database it is actually 10/12/2013.
Also when I call DateTime.Now in the code this is coming back as a US format (mm/dd/yyyy). I need everything to be consistent. How?
I have tried setting the culture info in the web config <globalization uiCulture="en-GB" culture="en-GB" /> but this is having no effect, some areas i am storing the date in sql server as GETDATE() and sometimes this is passed in as DateTime
I don't actually think you're dealing with incorrect behavior, you're most likely dealing with different TEXT representations of the SAME underlying DateTime or DATE item:
If Visual Studio is running on a system with en-US regional settings, it's insepectors will obviously use those settings when displaying dates in the debugger.
If you're looking at an SQL column with a data type of DATE, SQL might use the "SQL" standard representation for string, and that's why you see "2013-12-10"
When you're using Object Inspector to inspect the DateTime value selected into a control, Visual Studio is again using the system's settings to display that date. It can't show you the actual binary representation.
The crust of the problem:
Make sure you differentiate your actual date (stored in a DateTime variable or a DATE database column) from it's TEXT representation.
Make sure you get the correct date.
Make sure your application's users see the date in the expected format.
Learn to deal with the text representations of date that only you as a developer would see (the SQL-style representation and the Visual Studio inspector representation).
I have a table that has all the meeting schedules. I need to display the schedules in a Calendar on an Aspx page.
The calendar should:
allow the users to export the meetings to outlook
display time in different time zone specified in a dropdown list box.
have security based on different users' level of access (a field in the user table)
display in day, week, month, year.
display meetings in different colors for different meeting committees.
I use C#, .net 2.0, jQuery. Is there any existing code/add on that has already done this?
Thanks,
Fullcalendar will provide some of that functionality. I had to implement a similar calendar, and I used FullCalendar to provide the base functionality.
Day Pilot (Light) is free and open source. It doesn't do everything you need but at least you can expand on it. http://www.daypilot.org/demo/Lite/
DevExpress' Scheduler control would do most of this for you. It's not free though. Demos can be found here.
I am going to migrating a system to Windows Azure. And it will used UTC time for all existing function. Is there any way to set the time zone globally? Or I need to change all the code which display the time? My application will mainly serve in a specified timezone.
I have try apply the culture and uiculture on web.config. And it does not work.
Thanks.
As per the Windows Azure Team Blog - all the timing calculations/display etc have been moved to UTC.. https://azure.microsoft.com/en-us/blog/moving-to-coordinated-universal-time-utc/
I feel you would need to change the code which display the time as well which saves the time as well..
I have a website that displays the current date using the code Datetime.Now. From what I understand, Datetime.Now is supposed to display the current time as it would appear in the viewer's current locale.
At the moment, when I test on localhost, the website is correctly determining my location (en-nz) and displaying the right date. However, when I run the site live, I'm getting a different date all together.
So how does a system determine a viewer's locale and why is there a difference between how my site is displaying Datetime.Now locally and live?
DateTime.Now has the time of the server, but not the time of the client. If you want to detect the time of the client you need to use Javascript, either by detecting the time with it or calculating it using the time zones.
In your localhost works fine, since the server and the client are in the same PC/Time Zone
Hope it helps!
No, DateTime.Now will retrieve the current time in the local time zone of the machine it's running on. In other words, the web server in your case, assuming you're writing a web app (you haven't made it clear).
If you want to display it in the local time zone of a browser, you may well be best to send down DateTime.UtcNow and write some JavaScript to convert that to the local time... or just let JavaScript work out the current time on the user's system.
As far as I know, there's no way of getting the time zone from JavaScript accurately. You can get the current offset from UTC, but that's not the same as the time zone itself. (Offsets change due to things like DST; knowing the current offset doesn't tell you when DST will kick in.)
Maybe machines have different time settings? If development and live servers are in different locations, that's quite possible. As other answers say, DateTime.Now gets server time, not client time.