Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Setting British locale to get dates into my database correctly

$
0
0

Hey gang - 

I used to know how to do this, but like so much with core I'm trying to re-learn quickly and it's not going too well on this occasion. 

Situation: Developing in the UK on a Mac, set to British English. Deploying to Azure Web App located in UK West. I (stupidly) assumed that machine might be setup for British too but I'm thinking perhaps not.

I have a class called Season, looks like this.

    public class Season
    {

        public int SeasonID {get;set;}
        public string SeasonName {get;set;}
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
        public DateTime? FirstDay {get;set;}
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
        public DateTime? LastDay {get;set;}

    }

I've got an MVC Razor view with two three textboxes on, user fills them in and hits save. Back-end piece of code writes the name and the two dates into a SQL table. Running locally on Kestrel and writing to that Azure SQL works like a dream, UK format no problem. Once deployed, I only get US format dates - not helpful. 

In my startup.cs I have some stuff I got from StackOverflow which I thought would help, but alas not:

            app.UseRequestLocalization(
                new RequestLocalizationOptions() {
                    DefaultRequestCulture = new RequestCulture(
                        new CultureInfo("en-GB")) });

Back before Core I would have put my localisation stuff in web.config but I've not tried to do that yet because I was led to believe that web.config wasn't really that important any more. I'm quite prepared to hear that's wrong of course. Meantime if anyone can shed some light into my vast dark world I'd really appreciate it. Thanks.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>