I want to format the column using SharePoint online column JSON formatting.

Dinesh Talekar 1 Reputation point
2020-11-09T08:30:59.21+00:00

we using the jquery function as below

new Date().toLocaleString('en-US', {

          month : 'long', 
          day : 'numeric',
          year : 'numeric',
          hour: 'numeric',
          minute: 'numeric',
          timeZone: "US/Pacific"
        })

With the above jQuery function we can do the date formatting with the specific time zone.

Same as the above I do have the requirement.

I want to format the date column as per the specific time zone.

I am trying to achieve this with the SharePoint online Column JSON formatting.

But in json formatting we use toLocaleString(@currentField) and pass the @currentField field parameter to the toLocalString. but i want to achieve the functionality like which I can do with the jQuery.

Thanks in Advance.

Microsoft 365 and Office SharePoint For business Windows
Microsoft 365 and Office SharePoint Server Development
{count} votes

1 answer

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2020-11-10T02:26:06.963+00:00

    As far as I know, there is no original function to change the timezone, we could only change the timezone by calculation, like:

    {  
       "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
       "elmType": "div",  
       "txtContent": "=([$date]+6*60*60*1000)"    
    }  
    

    Since the time displayed in the SharePoint list will be affected by the computer time zone after we add the json format, you need to subtract the computer time zone first to get the UTC time, and then add and subtract according to the desired time zone. Note that the time unit for adding and subtracting is milliseconds.
    Example:
    My computer's time zone is UTC+8, I want to get the time in UTC-8.

    =([$date]-8*60*60*1000+(-8)*60*60*1000)  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.