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

Display time in MVC view .net core #2435


User avatar
0
robrechtbelien created

Hi, I set up the clockprovider to UTC and allow users to set their timezone. When I place a date in a viewmodel and I pass the UTC datetime to it, it doesn't display the time in the current user's timezone. It stays in UTC. Is there a function I need to use in the view? I don't want to use javascript for it.


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

    Hi,

    You can use this class to convert from UTC to user's timezone <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/f10fa5205c780bcc27adfe38aaae631f412eb7df/src/Abp/Timing/Timezone/TimeZoneConverter.cs">https://github.com/aspnetboilerplate/as ... nverter.cs</a>.

    It is better to create a shortcut method like @L and use it in your cshtml files.

  • User Avatar
    0
    robrechtbelien created

    Great, thx for the info. How can I handle the reverse? If a user posts a form with a date, the date is a utc date, but it has the value the user enterd. Should I update all dates in the controller and convert them from the user's timezone to utc? That seems quite inefficient.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    How to you get date input from user ? Do you use a datepicker or anything else ? Actually, if you are using UtcClockProvider, ABP should convert all datetimes to UTC when you post them to server.