Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to get date format based on user regional. #7495


User avatar
1
PMS created

Hi,

I changed code based on this changes https://aspnetboilerplate.com/Pages/Documents/Timing we have in my setting page we have time zone drop down.

We need that each user see dates in format which is standard for his regional settings.

We have date formate dd.MM.yyyy.

Can you please tell me how we can achive this? for example..... If user is from Europe then my aplication date format need to be dd.MM.yyyy . If user in India then my aplication date format need to be MM/dd/yyyy .


6 Answer(s)
  • User Avatar
    0
    PMS created

    Any update ?

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, can you share your project version and framework?

    it will be helpful if you can share the code that isnt working for you.

    e.g. the code that display datetime on the UI

  • User Avatar
    0
    PMS created

    Angular : 8.0.0 and core project (api ) : .net core 2.2

    My concern is there any global way/setting/something to change the date formate regional vise?

    let say I m using the moment to display the date .. and if I want to display the date like MM/DD/YYYY then I have to write the moment().formate('MM/DD/YYYY') also we can write L: 'DD/MM/YYYY' Now I want to keep the change the formate regional vise. IF I am in the USA and open the application has to show MM/DD/YYYY formate date same if I am in Europe then my application date format needs to be dd.MM.yyyy

    Please suggest any global way setting from table or file.

    Thanks In advance!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @PMS

    The date format must change according to language you select. AspNet Zero sets moments locale here https://github.com/aspnetzero/aspnet-zero-core/blob/dev/angular/src/AppPreBootstrap.ts#L155and then moment acts according to this locale.

  • User Avatar
    0
    PMS created

    Thanks For the replay.

    Some quetions are ariesed.

    1. From this we looks its change language but not based on the Browser regional if possible then plz give the steps or link somthing .
    2. If we do the language vise then what is the default formate for this ? We cant use moment().formate('MM/DD/YYYY') and moment(). Kindly Suggest How we can got this date formate dd.MM.yyyy default when I in Europe

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    For your second question, you must use L for formatting the dates, see https://momentjs.com/docs/#/customization/long-date-formats/. Don't use specific formats like MM/DD/YYYY or YYYY/MM/DD. The default format is the format for the default language in that case.

    Couldn't understand your #1 question I guess. Do you want to set the format according to users browser culture ?