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

Display Datetime as per the user selected timezone #11296


User avatar
0
[email protected] created

Am working with Asp.net core & jquery project I have added the Clock.Provider = ClockProviders.Utc; under MVC startup ConfigureServices method, and now am having difficulties to present any date with the user selected timezone. Any help would be appreciated


6 Answer(s)
  • User Avatar
    0
    [email protected] created

    and librarysettings is not being render and if i call it from the layout abp.clock.provider.supportsMultipleTimezone is coming undefined

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Are you trying to do that in a datatable or in cshtml ?

  • User Avatar
    0
    [email protected] created

    Hi,

    in cshtml

    Ive noticed that creationtime,lastmodificationdatetime are being converted to UTC, but any other custom dates no, and kindly note that am working with the Public project and ive implemeted the clock provider in both the MVC and Public projects.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    If you don't make any specific change and when you use ClockProviders.Utc, dates should be converted to UTC when saved to database.

    1. Could you share a sample Controller/AppService, its related method and input class which contains the date field ?
    2. Please also share the string value sent from client to server during the save operation.
  • User Avatar
    0
    [email protected] created

    input class public class CreateOrEditAvailabilityDto : EntityDto<int?> {

        public DateTime Day { get; set; }
    
        public DateTime Time { get; set; }
    
        public DateTime Datetime { get; set; }
    
        public bool Generated { get; set; }
    
        public string Timezone { get; set; }
    
        public AvailabilityStatusEnum Status { get; set; }
    
        public int SpecialistId { get; set; }
    
        public int ProductTypeId { get; set; }
    
    }
    
    **save function**
     public JsonResult SaveCalendar([FromBody] List&lt;CalendarItem&gt; list)
        {
            var OrgList = list.FindAll(x => x.type != "none" && x.type != "" && x.Id == 0);
            foreach (var item in OrgList)
            {
                CreateOrEditAvailabilityDto calendarItem = new CreateOrEditAvailabilityDto();
    
                calendarItem.Day = DateTime.Parse(item.day);
                calendarItem.Time = DateTime.Parse(item.time);
                calendarItem.Datetime =calendarItem.Datetime;
                calendarItem.SpecialistId = 0;
                calendarItem.Status = AvailabilityStatusEnum.Available;
                _availabilitiesAppService.CreateOrEdit(calendarItem);
            }
            return Json(list);
        }
        
       ** AppService method**
        
         protected virtual async Task Create(CreateOrEditAvailabilityDto input)
        {
            var availability = ObjectMapper.Map&lt;Availability&gt;(input);
    
            if (AbpSession.TenantId != null)
            {
                availability.TenantId = (int?)AbpSession.TenantId;
            }
    
            if (input.SpecialistId == 0)
            {
                availability.SpecialistId = _lookup_specialistRepository.FirstOrDefault(x => x.UserId == AbpSession.UserId).Id;
            }
    
            await _availabilityRepository.InsertAsync(availability);
    
        }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Could you also share a sample json data which causes this problem ?