How get DateTime.Now with “AM” not “ق.ظ”









up vote
1
down vote

favorite












I try to get DateTime.Now , but what I get is:




'23/05/2016 03:16:51 ق.ظ'




I want to have




'23/05/2016 03:16:51 AM'




or something like this










share|improve this question



















  • 6




    You can use DateTime.Now.ToString(string Format), and specify what format you want. Check MSDN for applicable formats.
    – raidensan
    May 23 '16 at 12:01






  • 2




    DateTime.Now.ToString(new CultureInfo("en-US"))
    – Tim Schmelter
    May 23 '16 at 12:07










  • Or possibly CultureInfo.InvariantCulture, depending on the context.
    – Matthew Watson
    May 23 '16 at 12:09






  • 1




    @raidensan That isn't enough. OP ought to specify the culture in this case.
    – Sriram Sakthivel
    May 23 '16 at 12:11










  • @SriramSakthivel then, there is a catch here. If I recall correctly the first output is from Persian calendar. If OP wants to just change the AM/PM specifier of Persian culture, he can change these from System Regional settings or, by specifying CultureInfo of app. I highly suspect that OP use DateTime.Now without giving any format at all.
    – raidensan
    May 23 '16 at 12:18














up vote
1
down vote

favorite












I try to get DateTime.Now , but what I get is:




'23/05/2016 03:16:51 ق.ظ'




I want to have




'23/05/2016 03:16:51 AM'




or something like this










share|improve this question



















  • 6




    You can use DateTime.Now.ToString(string Format), and specify what format you want. Check MSDN for applicable formats.
    – raidensan
    May 23 '16 at 12:01






  • 2




    DateTime.Now.ToString(new CultureInfo("en-US"))
    – Tim Schmelter
    May 23 '16 at 12:07










  • Or possibly CultureInfo.InvariantCulture, depending on the context.
    – Matthew Watson
    May 23 '16 at 12:09






  • 1




    @raidensan That isn't enough. OP ought to specify the culture in this case.
    – Sriram Sakthivel
    May 23 '16 at 12:11










  • @SriramSakthivel then, there is a catch here. If I recall correctly the first output is from Persian calendar. If OP wants to just change the AM/PM specifier of Persian culture, he can change these from System Regional settings or, by specifying CultureInfo of app. I highly suspect that OP use DateTime.Now without giving any format at all.
    – raidensan
    May 23 '16 at 12:18












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I try to get DateTime.Now , but what I get is:




'23/05/2016 03:16:51 ق.ظ'




I want to have




'23/05/2016 03:16:51 AM'




or something like this










share|improve this question















I try to get DateTime.Now , but what I get is:




'23/05/2016 03:16:51 ق.ظ'




I want to have




'23/05/2016 03:16:51 AM'




or something like this







c# datetime






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 15:05









Cœur

16.9k9102139




16.9k9102139










asked May 23 '16 at 11:59









ara

3716




3716







  • 6




    You can use DateTime.Now.ToString(string Format), and specify what format you want. Check MSDN for applicable formats.
    – raidensan
    May 23 '16 at 12:01






  • 2




    DateTime.Now.ToString(new CultureInfo("en-US"))
    – Tim Schmelter
    May 23 '16 at 12:07










  • Or possibly CultureInfo.InvariantCulture, depending on the context.
    – Matthew Watson
    May 23 '16 at 12:09






  • 1




    @raidensan That isn't enough. OP ought to specify the culture in this case.
    – Sriram Sakthivel
    May 23 '16 at 12:11










  • @SriramSakthivel then, there is a catch here. If I recall correctly the first output is from Persian calendar. If OP wants to just change the AM/PM specifier of Persian culture, he can change these from System Regional settings or, by specifying CultureInfo of app. I highly suspect that OP use DateTime.Now without giving any format at all.
    – raidensan
    May 23 '16 at 12:18












  • 6




    You can use DateTime.Now.ToString(string Format), and specify what format you want. Check MSDN for applicable formats.
    – raidensan
    May 23 '16 at 12:01






  • 2




    DateTime.Now.ToString(new CultureInfo("en-US"))
    – Tim Schmelter
    May 23 '16 at 12:07










  • Or possibly CultureInfo.InvariantCulture, depending on the context.
    – Matthew Watson
    May 23 '16 at 12:09






  • 1




    @raidensan That isn't enough. OP ought to specify the culture in this case.
    – Sriram Sakthivel
    May 23 '16 at 12:11










  • @SriramSakthivel then, there is a catch here. If I recall correctly the first output is from Persian calendar. If OP wants to just change the AM/PM specifier of Persian culture, he can change these from System Regional settings or, by specifying CultureInfo of app. I highly suspect that OP use DateTime.Now without giving any format at all.
    – raidensan
    May 23 '16 at 12:18







6




6




You can use DateTime.Now.ToString(string Format), and specify what format you want. Check MSDN for applicable formats.
– raidensan
May 23 '16 at 12:01




You can use DateTime.Now.ToString(string Format), and specify what format you want. Check MSDN for applicable formats.
– raidensan
May 23 '16 at 12:01




2




2




DateTime.Now.ToString(new CultureInfo("en-US"))
– Tim Schmelter
May 23 '16 at 12:07




DateTime.Now.ToString(new CultureInfo("en-US"))
– Tim Schmelter
May 23 '16 at 12:07












Or possibly CultureInfo.InvariantCulture, depending on the context.
– Matthew Watson
May 23 '16 at 12:09




Or possibly CultureInfo.InvariantCulture, depending on the context.
– Matthew Watson
May 23 '16 at 12:09




1




1




@raidensan That isn't enough. OP ought to specify the culture in this case.
– Sriram Sakthivel
May 23 '16 at 12:11




@raidensan That isn't enough. OP ought to specify the culture in this case.
– Sriram Sakthivel
May 23 '16 at 12:11












@SriramSakthivel then, there is a catch here. If I recall correctly the first output is from Persian calendar. If OP wants to just change the AM/PM specifier of Persian culture, he can change these from System Regional settings or, by specifying CultureInfo of app. I highly suspect that OP use DateTime.Now without giving any format at all.
– raidensan
May 23 '16 at 12:18




@SriramSakthivel then, there is a catch here. If I recall correctly the first output is from Persian calendar. If OP wants to just change the AM/PM specifier of Persian culture, he can change these from System Regional settings or, by specifying CultureInfo of app. I highly suspect that OP use DateTime.Now without giving any format at all.
– raidensan
May 23 '16 at 12:18












3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










Then you current culture seems to be an arabic one. You can use the overload of DateTime.ToString:



var enUsCulture = new CultureInfo("en-US");
string result = DateTime.Now.ToString( enUsCulture );


an an alternative you could pass the exact format with CultureInfo.InvariantCulture(to avoid that / will be replaced with your current culture's date separator):



string result = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);


The InvariantCulture avoids that the "/" custom format specifier will cause / to be replaced with your current culture's date separator.






share|improve this answer






















  • "To be sure": DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
    – Corak
    May 23 '16 at 12:13






  • 1




    Not the invariant culture?
    – stuartd
    May 23 '16 at 12:16










  • @stuartd: no, it does not use the AM/PM designator. But i've used a different approach where InvariantCulture would be useful to supress the the "/" custom format specifier
    – Tim Schmelter
    May 23 '16 at 12:24










  • thank you very much :)
    – ara
    May 23 '16 at 12:47

















up vote
0
down vote













You could create a specific CultureInfo with your requirements starting from the CurrentCulture



CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.LCID);
ci.DateTimeFormat.AMDesignator = "AM";
ci.DateTimeFormat.PMDesignator = "PM";
ci.DateTimeFormat.LongTimePattern = "HH:mm:ss tt";
string result = DateTime.Now.ToString(ci);
Console.WriteLine(result);





share|improve this answer




















  • thank you , it works too, but I had one way to choose
    – ara
    May 23 '16 at 12:48

















up vote
0
down vote













I think CultureInfo.InvariantCulture is the key here



 DateTime now = DateTime.Now;
string result = now.ToString("dd MMM yyyy hh:mm tt", CultureInfo.InvariantCulture);
Console.WriteLine(result);


This should give you "23 May 2016 02:32 PM", you can further edit the date and time by using other setting in the string format specifier. But keep InvarianCulture and tt in order to recieve AP/PM.



For all possible formats and some examples check these links



https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx



http://www.dotnetperls.com/datetime-format






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',
    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%2f37390425%2fhow-get-datetime-now-with-am-not-%25d9%2582-%25d8%25b8%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    Then you current culture seems to be an arabic one. You can use the overload of DateTime.ToString:



    var enUsCulture = new CultureInfo("en-US");
    string result = DateTime.Now.ToString( enUsCulture );


    an an alternative you could pass the exact format with CultureInfo.InvariantCulture(to avoid that / will be replaced with your current culture's date separator):



    string result = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);


    The InvariantCulture avoids that the "/" custom format specifier will cause / to be replaced with your current culture's date separator.






    share|improve this answer






















    • "To be sure": DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
      – Corak
      May 23 '16 at 12:13






    • 1




      Not the invariant culture?
      – stuartd
      May 23 '16 at 12:16










    • @stuartd: no, it does not use the AM/PM designator. But i've used a different approach where InvariantCulture would be useful to supress the the "/" custom format specifier
      – Tim Schmelter
      May 23 '16 at 12:24










    • thank you very much :)
      – ara
      May 23 '16 at 12:47














    up vote
    1
    down vote



    accepted










    Then you current culture seems to be an arabic one. You can use the overload of DateTime.ToString:



    var enUsCulture = new CultureInfo("en-US");
    string result = DateTime.Now.ToString( enUsCulture );


    an an alternative you could pass the exact format with CultureInfo.InvariantCulture(to avoid that / will be replaced with your current culture's date separator):



    string result = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);


    The InvariantCulture avoids that the "/" custom format specifier will cause / to be replaced with your current culture's date separator.






    share|improve this answer






















    • "To be sure": DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
      – Corak
      May 23 '16 at 12:13






    • 1




      Not the invariant culture?
      – stuartd
      May 23 '16 at 12:16










    • @stuartd: no, it does not use the AM/PM designator. But i've used a different approach where InvariantCulture would be useful to supress the the "/" custom format specifier
      – Tim Schmelter
      May 23 '16 at 12:24










    • thank you very much :)
      – ara
      May 23 '16 at 12:47












    up vote
    1
    down vote



    accepted







    up vote
    1
    down vote



    accepted






    Then you current culture seems to be an arabic one. You can use the overload of DateTime.ToString:



    var enUsCulture = new CultureInfo("en-US");
    string result = DateTime.Now.ToString( enUsCulture );


    an an alternative you could pass the exact format with CultureInfo.InvariantCulture(to avoid that / will be replaced with your current culture's date separator):



    string result = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);


    The InvariantCulture avoids that the "/" custom format specifier will cause / to be replaced with your current culture's date separator.






    share|improve this answer














    Then you current culture seems to be an arabic one. You can use the overload of DateTime.ToString:



    var enUsCulture = new CultureInfo("en-US");
    string result = DateTime.Now.ToString( enUsCulture );


    an an alternative you could pass the exact format with CultureInfo.InvariantCulture(to avoid that / will be replaced with your current culture's date separator):



    string result = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);


    The InvariantCulture avoids that the "/" custom format specifier will cause / to be replaced with your current culture's date separator.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 23 '16 at 12:22

























    answered May 23 '16 at 12:09









    Tim Schmelter

    357k44448705




    357k44448705











    • "To be sure": DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
      – Corak
      May 23 '16 at 12:13






    • 1




      Not the invariant culture?
      – stuartd
      May 23 '16 at 12:16










    • @stuartd: no, it does not use the AM/PM designator. But i've used a different approach where InvariantCulture would be useful to supress the the "/" custom format specifier
      – Tim Schmelter
      May 23 '16 at 12:24










    • thank you very much :)
      – ara
      May 23 '16 at 12:47
















    • "To be sure": DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
      – Corak
      May 23 '16 at 12:13






    • 1




      Not the invariant culture?
      – stuartd
      May 23 '16 at 12:16










    • @stuartd: no, it does not use the AM/PM designator. But i've used a different approach where InvariantCulture would be useful to supress the the "/" custom format specifier
      – Tim Schmelter
      May 23 '16 at 12:24










    • thank you very much :)
      – ara
      May 23 '16 at 12:47















    "To be sure": DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
    – Corak
    May 23 '16 at 12:13




    "To be sure": DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
    – Corak
    May 23 '16 at 12:13




    1




    1




    Not the invariant culture?
    – stuartd
    May 23 '16 at 12:16




    Not the invariant culture?
    – stuartd
    May 23 '16 at 12:16












    @stuartd: no, it does not use the AM/PM designator. But i've used a different approach where InvariantCulture would be useful to supress the the "/" custom format specifier
    – Tim Schmelter
    May 23 '16 at 12:24




    @stuartd: no, it does not use the AM/PM designator. But i've used a different approach where InvariantCulture would be useful to supress the the "/" custom format specifier
    – Tim Schmelter
    May 23 '16 at 12:24












    thank you very much :)
    – ara
    May 23 '16 at 12:47




    thank you very much :)
    – ara
    May 23 '16 at 12:47












    up vote
    0
    down vote













    You could create a specific CultureInfo with your requirements starting from the CurrentCulture



    CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.LCID);
    ci.DateTimeFormat.AMDesignator = "AM";
    ci.DateTimeFormat.PMDesignator = "PM";
    ci.DateTimeFormat.LongTimePattern = "HH:mm:ss tt";
    string result = DateTime.Now.ToString(ci);
    Console.WriteLine(result);





    share|improve this answer




















    • thank you , it works too, but I had one way to choose
      – ara
      May 23 '16 at 12:48














    up vote
    0
    down vote













    You could create a specific CultureInfo with your requirements starting from the CurrentCulture



    CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.LCID);
    ci.DateTimeFormat.AMDesignator = "AM";
    ci.DateTimeFormat.PMDesignator = "PM";
    ci.DateTimeFormat.LongTimePattern = "HH:mm:ss tt";
    string result = DateTime.Now.ToString(ci);
    Console.WriteLine(result);





    share|improve this answer




















    • thank you , it works too, but I had one way to choose
      – ara
      May 23 '16 at 12:48












    up vote
    0
    down vote










    up vote
    0
    down vote









    You could create a specific CultureInfo with your requirements starting from the CurrentCulture



    CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.LCID);
    ci.DateTimeFormat.AMDesignator = "AM";
    ci.DateTimeFormat.PMDesignator = "PM";
    ci.DateTimeFormat.LongTimePattern = "HH:mm:ss tt";
    string result = DateTime.Now.ToString(ci);
    Console.WriteLine(result);





    share|improve this answer












    You could create a specific CultureInfo with your requirements starting from the CurrentCulture



    CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.LCID);
    ci.DateTimeFormat.AMDesignator = "AM";
    ci.DateTimeFormat.PMDesignator = "PM";
    ci.DateTimeFormat.LongTimePattern = "HH:mm:ss tt";
    string result = DateTime.Now.ToString(ci);
    Console.WriteLine(result);






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered May 23 '16 at 12:20









    Steve

    178k16149216




    178k16149216











    • thank you , it works too, but I had one way to choose
      – ara
      May 23 '16 at 12:48
















    • thank you , it works too, but I had one way to choose
      – ara
      May 23 '16 at 12:48















    thank you , it works too, but I had one way to choose
    – ara
    May 23 '16 at 12:48




    thank you , it works too, but I had one way to choose
    – ara
    May 23 '16 at 12:48










    up vote
    0
    down vote













    I think CultureInfo.InvariantCulture is the key here



     DateTime now = DateTime.Now;
    string result = now.ToString("dd MMM yyyy hh:mm tt", CultureInfo.InvariantCulture);
    Console.WriteLine(result);


    This should give you "23 May 2016 02:32 PM", you can further edit the date and time by using other setting in the string format specifier. But keep InvarianCulture and tt in order to recieve AP/PM.



    For all possible formats and some examples check these links



    https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx



    http://www.dotnetperls.com/datetime-format






    share|improve this answer
























      up vote
      0
      down vote













      I think CultureInfo.InvariantCulture is the key here



       DateTime now = DateTime.Now;
      string result = now.ToString("dd MMM yyyy hh:mm tt", CultureInfo.InvariantCulture);
      Console.WriteLine(result);


      This should give you "23 May 2016 02:32 PM", you can further edit the date and time by using other setting in the string format specifier. But keep InvarianCulture and tt in order to recieve AP/PM.



      For all possible formats and some examples check these links



      https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx



      http://www.dotnetperls.com/datetime-format






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        I think CultureInfo.InvariantCulture is the key here



         DateTime now = DateTime.Now;
        string result = now.ToString("dd MMM yyyy hh:mm tt", CultureInfo.InvariantCulture);
        Console.WriteLine(result);


        This should give you "23 May 2016 02:32 PM", you can further edit the date and time by using other setting in the string format specifier. But keep InvarianCulture and tt in order to recieve AP/PM.



        For all possible formats and some examples check these links



        https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx



        http://www.dotnetperls.com/datetime-format






        share|improve this answer












        I think CultureInfo.InvariantCulture is the key here



         DateTime now = DateTime.Now;
        string result = now.ToString("dd MMM yyyy hh:mm tt", CultureInfo.InvariantCulture);
        Console.WriteLine(result);


        This should give you "23 May 2016 02:32 PM", you can further edit the date and time by using other setting in the string format specifier. But keep InvarianCulture and tt in order to recieve AP/PM.



        For all possible formats and some examples check these links



        https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx



        http://www.dotnetperls.com/datetime-format







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 23 '16 at 12:30









        NoobPointerException

        16111




        16111



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37390425%2fhow-get-datetime-now-with-am-not-%25d9%2582-%25d8%25b8%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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto