Base solution for your next web application
Open Closed

Server side format Date/Time / Angular 2 #2966


User avatar
0
paradoxit created

Please can you advise how I can return a localized formatted date on the server side from an IApplicationService?

I can do this locally in Angular using moment.js but I want to format the server side date to export a PDF.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    In your case it is better to return date values as string, otherwise ABP will normalize datetime values. You can convert datetime values to string using culture like this:

    CultureInfo enUS= new CultureInfo("en-US");
    datetime.ToString("d", enUS);
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    paradoxit created

    Hi ismcagdas,

    Thank you for replying. I don't however know what the current logged in users culture is from the server side, how can I find this out?

    Kind regards, David Hawkins

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can get it from Current Thread's Culture or CultureInfo.CurrentCulture.

    Thanks.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    paradoxit created

    Thanks ismcagdas

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)