Make an application independent from windows's culture












-1















I'm creating an application in VB.NET, .NET 4.0.



This application uses too often the DateTime type.



The problem is that I want to work with dates in a specific format dd/MM/yyyy.



If a set ( in Windows ) the correct Regional and settings everything is ok.
But if user change this Windows configurations, my application fails.
So is there any way to make my application independent from what is configured in Windows for Regional and settings ?
Thank you !










share|improve this question




















  • 1





    Dates don't have a format. If your application fails when the culture changes then it's because you're doing something wrong. Format is only an issue for dates when you are converting to or from a String and there's no reason for that to have an effect on your application. For instance, if you want the user to edit dates in a WinForms UI then you use a DateTimePicker. It can display the date to the user in whatever format they expect based on system settings and you just use the Value property, which is type DateTime, and the format has no effect at all.

    – jmcilhinney
    Nov 25 '18 at 14:42











  • Explain to us what you're doing and we will explain to you exactly what you're doing wrong. Anywhere in your application that the code depends on a specific format, you're almost certainly doing something wrong there.

    – jmcilhinney
    Nov 25 '18 at 14:43











  • @jmcilhinney I'm reading dates as strings from an text file , and after I convert them. Dim dt As Date = Date.ParseExact(s, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture) , If for example s="25/12/2018" , this line of code is ok with some Regional settings but produce exception with some others , but for my application rule this is a correct Date.

    – Adriano
    Nov 25 '18 at 14:56













  • Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture

    – JohnyL
    Nov 25 '18 at 14:57











  • If you don't want to be affected by the current culture then why specify the current culture when doing the conversion? Don't specify a culture at all, i.e. use Nothing for the third argument. I would imagine that using the invariant culture or a specific culture that uses that date format, e.g. en-GB, would work too.

    – jmcilhinney
    Nov 25 '18 at 15:02
















-1















I'm creating an application in VB.NET, .NET 4.0.



This application uses too often the DateTime type.



The problem is that I want to work with dates in a specific format dd/MM/yyyy.



If a set ( in Windows ) the correct Regional and settings everything is ok.
But if user change this Windows configurations, my application fails.
So is there any way to make my application independent from what is configured in Windows for Regional and settings ?
Thank you !










share|improve this question




















  • 1





    Dates don't have a format. If your application fails when the culture changes then it's because you're doing something wrong. Format is only an issue for dates when you are converting to or from a String and there's no reason for that to have an effect on your application. For instance, if you want the user to edit dates in a WinForms UI then you use a DateTimePicker. It can display the date to the user in whatever format they expect based on system settings and you just use the Value property, which is type DateTime, and the format has no effect at all.

    – jmcilhinney
    Nov 25 '18 at 14:42











  • Explain to us what you're doing and we will explain to you exactly what you're doing wrong. Anywhere in your application that the code depends on a specific format, you're almost certainly doing something wrong there.

    – jmcilhinney
    Nov 25 '18 at 14:43











  • @jmcilhinney I'm reading dates as strings from an text file , and after I convert them. Dim dt As Date = Date.ParseExact(s, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture) , If for example s="25/12/2018" , this line of code is ok with some Regional settings but produce exception with some others , but for my application rule this is a correct Date.

    – Adriano
    Nov 25 '18 at 14:56













  • Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture

    – JohnyL
    Nov 25 '18 at 14:57











  • If you don't want to be affected by the current culture then why specify the current culture when doing the conversion? Don't specify a culture at all, i.e. use Nothing for the third argument. I would imagine that using the invariant culture or a specific culture that uses that date format, e.g. en-GB, would work too.

    – jmcilhinney
    Nov 25 '18 at 15:02














-1












-1








-1


1






I'm creating an application in VB.NET, .NET 4.0.



This application uses too often the DateTime type.



The problem is that I want to work with dates in a specific format dd/MM/yyyy.



If a set ( in Windows ) the correct Regional and settings everything is ok.
But if user change this Windows configurations, my application fails.
So is there any way to make my application independent from what is configured in Windows for Regional and settings ?
Thank you !










share|improve this question
















I'm creating an application in VB.NET, .NET 4.0.



This application uses too often the DateTime type.



The problem is that I want to work with dates in a specific format dd/MM/yyyy.



If a set ( in Windows ) the correct Regional and settings everything is ok.
But if user change this Windows configurations, my application fails.
So is there any way to make my application independent from what is configured in Windows for Regional and settings ?
Thank you !







vb.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 17:56









Pragmateek

9,26685488




9,26685488










asked Nov 25 '18 at 14:36









AdrianoAdriano

277




277








  • 1





    Dates don't have a format. If your application fails when the culture changes then it's because you're doing something wrong. Format is only an issue for dates when you are converting to or from a String and there's no reason for that to have an effect on your application. For instance, if you want the user to edit dates in a WinForms UI then you use a DateTimePicker. It can display the date to the user in whatever format they expect based on system settings and you just use the Value property, which is type DateTime, and the format has no effect at all.

    – jmcilhinney
    Nov 25 '18 at 14:42











  • Explain to us what you're doing and we will explain to you exactly what you're doing wrong. Anywhere in your application that the code depends on a specific format, you're almost certainly doing something wrong there.

    – jmcilhinney
    Nov 25 '18 at 14:43











  • @jmcilhinney I'm reading dates as strings from an text file , and after I convert them. Dim dt As Date = Date.ParseExact(s, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture) , If for example s="25/12/2018" , this line of code is ok with some Regional settings but produce exception with some others , but for my application rule this is a correct Date.

    – Adriano
    Nov 25 '18 at 14:56













  • Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture

    – JohnyL
    Nov 25 '18 at 14:57











  • If you don't want to be affected by the current culture then why specify the current culture when doing the conversion? Don't specify a culture at all, i.e. use Nothing for the third argument. I would imagine that using the invariant culture or a specific culture that uses that date format, e.g. en-GB, would work too.

    – jmcilhinney
    Nov 25 '18 at 15:02














  • 1





    Dates don't have a format. If your application fails when the culture changes then it's because you're doing something wrong. Format is only an issue for dates when you are converting to or from a String and there's no reason for that to have an effect on your application. For instance, if you want the user to edit dates in a WinForms UI then you use a DateTimePicker. It can display the date to the user in whatever format they expect based on system settings and you just use the Value property, which is type DateTime, and the format has no effect at all.

    – jmcilhinney
    Nov 25 '18 at 14:42











  • Explain to us what you're doing and we will explain to you exactly what you're doing wrong. Anywhere in your application that the code depends on a specific format, you're almost certainly doing something wrong there.

    – jmcilhinney
    Nov 25 '18 at 14:43











  • @jmcilhinney I'm reading dates as strings from an text file , and after I convert them. Dim dt As Date = Date.ParseExact(s, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture) , If for example s="25/12/2018" , this line of code is ok with some Regional settings but produce exception with some others , but for my application rule this is a correct Date.

    – Adriano
    Nov 25 '18 at 14:56













  • Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture

    – JohnyL
    Nov 25 '18 at 14:57











  • If you don't want to be affected by the current culture then why specify the current culture when doing the conversion? Don't specify a culture at all, i.e. use Nothing for the third argument. I would imagine that using the invariant culture or a specific culture that uses that date format, e.g. en-GB, would work too.

    – jmcilhinney
    Nov 25 '18 at 15:02








1




1





Dates don't have a format. If your application fails when the culture changes then it's because you're doing something wrong. Format is only an issue for dates when you are converting to or from a String and there's no reason for that to have an effect on your application. For instance, if you want the user to edit dates in a WinForms UI then you use a DateTimePicker. It can display the date to the user in whatever format they expect based on system settings and you just use the Value property, which is type DateTime, and the format has no effect at all.

– jmcilhinney
Nov 25 '18 at 14:42





Dates don't have a format. If your application fails when the culture changes then it's because you're doing something wrong. Format is only an issue for dates when you are converting to or from a String and there's no reason for that to have an effect on your application. For instance, if you want the user to edit dates in a WinForms UI then you use a DateTimePicker. It can display the date to the user in whatever format they expect based on system settings and you just use the Value property, which is type DateTime, and the format has no effect at all.

– jmcilhinney
Nov 25 '18 at 14:42













Explain to us what you're doing and we will explain to you exactly what you're doing wrong. Anywhere in your application that the code depends on a specific format, you're almost certainly doing something wrong there.

– jmcilhinney
Nov 25 '18 at 14:43





Explain to us what you're doing and we will explain to you exactly what you're doing wrong. Anywhere in your application that the code depends on a specific format, you're almost certainly doing something wrong there.

– jmcilhinney
Nov 25 '18 at 14:43













@jmcilhinney I'm reading dates as strings from an text file , and after I convert them. Dim dt As Date = Date.ParseExact(s, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture) , If for example s="25/12/2018" , this line of code is ok with some Regional settings but produce exception with some others , but for my application rule this is a correct Date.

– Adriano
Nov 25 '18 at 14:56







@jmcilhinney I'm reading dates as strings from an text file , and after I convert them. Dim dt As Date = Date.ParseExact(s, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture) , If for example s="25/12/2018" , this line of code is ok with some Regional settings but produce exception with some others , but for my application rule this is a correct Date.

– Adriano
Nov 25 '18 at 14:56















Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture

– JohnyL
Nov 25 '18 at 14:57





Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture

– JohnyL
Nov 25 '18 at 14:57













If you don't want to be affected by the current culture then why specify the current culture when doing the conversion? Don't specify a culture at all, i.e. use Nothing for the third argument. I would imagine that using the invariant culture or a specific culture that uses that date format, e.g. en-GB, would work too.

– jmcilhinney
Nov 25 '18 at 15:02





If you don't want to be affected by the current culture then why specify the current culture when doing the conversion? Don't specify a culture at all, i.e. use Nothing for the third argument. I would imagine that using the invariant culture or a specific culture that uses that date format, e.g. en-GB, would work too.

– jmcilhinney
Nov 25 '18 at 15:02












1 Answer
1






active

oldest

votes


















0














I used to have a similar problem some time ago, but not a DateTime issue, was more related to calculations, the decimal point .. Although some of the examples in the above comments worked fine, specifically the CultureInfo.InvariantCulture I found it far easier to scrap all those and simply add this to my main form Load:



Application.CurrentCulture = New Globalization.CultureInfo("en-GB")


Problem solved ;-)






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53468571%2fmake-an-application-independent-from-windowss-culture%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I used to have a similar problem some time ago, but not a DateTime issue, was more related to calculations, the decimal point .. Although some of the examples in the above comments worked fine, specifically the CultureInfo.InvariantCulture I found it far easier to scrap all those and simply add this to my main form Load:



    Application.CurrentCulture = New Globalization.CultureInfo("en-GB")


    Problem solved ;-)






    share|improve this answer




























      0














      I used to have a similar problem some time ago, but not a DateTime issue, was more related to calculations, the decimal point .. Although some of the examples in the above comments worked fine, specifically the CultureInfo.InvariantCulture I found it far easier to scrap all those and simply add this to my main form Load:



      Application.CurrentCulture = New Globalization.CultureInfo("en-GB")


      Problem solved ;-)






      share|improve this answer


























        0












        0








        0







        I used to have a similar problem some time ago, but not a DateTime issue, was more related to calculations, the decimal point .. Although some of the examples in the above comments worked fine, specifically the CultureInfo.InvariantCulture I found it far easier to scrap all those and simply add this to my main form Load:



        Application.CurrentCulture = New Globalization.CultureInfo("en-GB")


        Problem solved ;-)






        share|improve this answer













        I used to have a similar problem some time ago, but not a DateTime issue, was more related to calculations, the decimal point .. Although some of the examples in the above comments worked fine, specifically the CultureInfo.InvariantCulture I found it far easier to scrap all those and simply add this to my main form Load:



        Application.CurrentCulture = New Globalization.CultureInfo("en-GB")


        Problem solved ;-)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 8:55









        video.babavideo.baba

        517238




        517238
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53468571%2fmake-an-application-independent-from-windowss-culture%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            Refactoring coordinates for Minecraft Pi buildings written in Python