Setting Timezone in Windows Azure

來源:互聯網
上載者:User
Introduction

I strongly believe that in most application we are building, we would need to store date and time. In some application, date and time play very important role, for instance: rental-similar application which could result big impact if date and time are incorrect. In other kinds of application, date and time may not be playing very significant role, for example: some of them is just as informational purpose, when the data is actually inserted in the system.

Regardless the importance level we discussed above, one essential factor that we need to be considered is the timezone of the system. Whether setting it as local country timezone or other timezone such as UTC / GMT, we would need to determine the it, typically on the server where our application is hosted.

Thus, when we type “DateTime.Now” inside your code, we should be able to get the correct result.

Timezone in Windows Azure

No matter which data center we selected in Windows Azure (remember, Windows Azure has 6 data centers world wide: 2 in America, 2 in Europe, and 2 in Asia), by default, Windows Azure VM would provide us UTC timezone.

If you are considering migrating your app to Windows Azure, you should ask yourself now what timezone your current application set. If it’s on UTC, you are safe, nothing to worry.

However, if you are running local time, (for example in Singapore, it’s UTC + 8 hour) and you want to ensure the consistency of your current data, then you will need to be cautious. You have “at least” 2 choice to go:

  1. Use UTC on your app, which mean you would need to convert your current date/time data to UTC.
  2. To set your preferred timezone in Windows Azure (it could be your local time).

I bet most of you will decline the first options .

How to set timezone in Windows Azure

Alright, I assume we go with option 2. To set timezone in Windows Azure, I believe there are actually a few waysvia Powershell or by modifying registry. Honestly, I’ve not tried these option on Windows Azure, yet I am not pretty sure if it could be applied in Windows Azure. But there’s an option that is definitely working well.

Okay, there’s actually a command utility called “tzutil” that can be used to change timezone. Please take note that this command is only applicable in Windows 7 and Windows Server 2008 R2.

TZUTIL

You may try to run it using your command prompt by typing “tzutil /?” for the information.

To change to your preferred timzeon, simply run the following command.

tzutil /s "Singapore Standard Time" 
Run it as Start-up task

In Windows Azure, we would need to run this command as start-up task, to ensure that when is starting up, the command will be executed first.

1. To do that, create a empty file (using notepad), and paste the above tzutil command inside, just save the file as settimezone.cmd inside your Windows Azure Project.

In your project, ensure that this file is included, if not you’ll need to include it manually.

2. The next step is to set the properties of this file to Copy Always. This is to ensure that the file will be included when project is packaged before deployment.

3. Subsequently, we would need to tell Windows Azure to run the start-up task. This could be achieved by adding the following start-up section inside your ServiceDefinition.csdef file.

4. Using Windows Server 2008  R2 VM Images

At earlier, I mentioned that the tzutil is only available in Windows 7 and Windows Server 2008 R2. Windows 7 is definitely out of context as there’s no such OS in Windows Azure.

Windows Azure at this moment allows us to choose either Windows Server 2008 or Windows Server 2008 R2. Both of them are running on 64 bit architecture.

By default (if you are not modifying anything in your configuration file), Windows Server 2008 will be selected.

In order to use tzutil, we would need to set the VM running as Windows Server 2008 R2. To do that, simply navigate to the ServiceConfiguration.cscfg file. In the ServiceConfiguration section, change the osFamily from 1 to 2.

*1 = Win 2008, while 2 = Win 2008 R2

We would also need to set the version of the OS. If you not preferring any OS, you can just simply put * and it will automatically perform update for you when there’s patch / new version of guest OS released.

5. Verification

If everything runs well, you should be getting your preferred timezone as expected.

Here’s how it’s look like, when I performed remote desktop to my Windows Azure VM.

What’s next?

In the app level, your are safe since you’ve successfully configure the timezone of your VM. But how about database level? What if there’s any stored procedure / function inside your code, use “getdate()” function?

I’ll discussed more on this topic in the next post. Stay tune…

Share this post:  |  |  |  | Published Sunday, June 26, 2011 2:56 PM by WelyFiled under: Windows Azure, SQL Azure, Windows Azure PlatformComments# Managing Timezone in SQL AzureSunday, July 10, 2011 8:29 PM by Wely Lau

In the last post, I showed you how to set timezone in Windows Azure . In this post, I would like to show

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.