未加星标

Locale Settings in Azure Functions

字体大小 | |
[系统(windows) 所属分类 系统(windows) | 发布者 店小二05 | 时间 2019 | 作者 红领巾 ] 0人收藏点击收藏
Locale Settings in Azure Functions DISCLAIMER: This post is purely a personal opinion, not representing or affiliating my employer’s.

PaaS (Platform as a Service) like Azure Functions is a fully-managed service, so we don’t have to do maintenance efforts. This often implies that there are something we can’t configure. One of these limitations is locale. Throughout this post, I’m going to talk about handling locale in Azure Functions. Let’s have a look at the following date format. How can you interpret it?

11/12/13

Depending on our culture (or locale), this can be translated in different ways:

ko-KR en-US en-AU

If we develop a new application, we follow ISO 8601 format not to be confused so that in general we use the date/time format like yyyy-MM-ddTHH:mm:ss.fffzzz . However, not every system follows this format. In many integration scenario, we have to deal with legacy systems that uses localised date/time formatted values. Even worse, if we handle those legacy data on the cloud like Azure Functions, this must be properly handled; otherwise it will be in trouble. Let’s have a look at the code below.

{ "date": "11/12/13" }

If we use the payload like above, how does this date format get parsed?

If your dev machine’s default locale is set to ko-KR , it will display like:

Input: 2011-12-13T00:00:00.0000000+11:00

If yours is en-AU , then you will see like:

Input: 2013-12-11T00:00:00.0000000+00:00

OK. What if we deploy this code into Azure Function instance?

Input: 2013-11-12T00:00:00.0000000+00:00

As you might have expected, it follows the US locale, en-US . If our data only deals with Australian locale, ko-KR ? There’s no way to change the locale of an Azure Function instance. In other words, we should handle this in the code level. Fortunately, we have Thread.CurrentThread.CurrentCulture , so we need to change this value. Let’s have a look at this code below:

Like the code above, we can simply add one line that changes the default locale, en-US , to en-AU . Once deployed, it returns the expected result.

Input: 2013-12-11T00:00:00.0000000+00:00

Easy, huh?

Related

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

代码区博客精选文章
分页:12
转载请注明
本文标题:Locale Settings in Azure Functions
本站链接:https://www.codesec.net/view/627927.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(36)