当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:如何将日期格式更改为“DD/MM/YYYY”?

作者:精品下载站 日期:2024-12-14 15:02:13 浏览:13 分类:玩电脑

SharePoint Online:如何将日期格式更改为“DD/MM/YYYY”?


要求:在 SharePoint Online 中将日期格式更改为“DD/MM/YYYY”。

如何在SharePoint Online中设置日期格式?

默认情况下,SharePoint Online 网站以美国格式 (MM/DD/YYYY) 显示日期。您可能需要根据您所在的国家/地区更改日期格式。在 SharePoint Online 中更改日期格式的第一步是更改网站集的区域设置。

让我们看看如何设置 SharePoint Online 或 OneDrive 网站的日期格式:

  1. 转到要更改其日期格式的 SharePoint Online 网站集。
  2. 单击“设置”齿轮 >> 单击“站点信息”>> 查看所有站点设置(URL 快捷方式:/_layouts/15/settings.aspx)。
  3. 在“站点设置”页面的“站点管理”下,单击“区域设置”链接。
  4. 单击区域设置下拉列表箭头并选择显示日期的区域设置。例如,英语、英国。您还可以设置其他设置,例如时区。

    [玩转系统] SharePoint Online:如何将日期格式更改为“DD/MM/YYYY”?

  5. 单击底部的“确定”按钮保存更改。这会更改整个子网站上各处的日期字段,例如列表、包括创建/修改的列、回收站等。

    [玩转系统] SharePoint Online:如何将日期格式更改为“DD/MM/YYYY”?

很简单吧?痛苦的部分是应该为每个站点(子站点)配置区域设置!更改顶级站点中的区域设置不会自动传播其子站点中的更改。

使用 PowerShell 更改 SharePoint Online 中的日期格式

以下是如何使用 PowerShell 更改 SharePoint Online 网站中的日期格式(区域设置):


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Config parameters for SharePoint Online Site URL and Locale
$SiteURL = "https://Crescent.sharepoint.com"
$LocaleID ="2057" #English - United Kingdom
 
#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
   
#Set up the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = $credentials

#Get Regional Settings of the Web
$Web = $Ctx.Web
$Ctx.Load($web)
$Ctx.Load($Web.RegionalSettings)
$ctx.ExecuteQuery()
 
#Update the LocaleID of the site
$Web.RegionalSettings.LocaleId = $LocaleID
$Web.Update()
$Ctx.ExecuteQuery() 

您创建的任何新子网站都将从其父网站继承区域设置!

请参阅此 Microsoft 文档了解所有可用的区域设置 ID:https://docs.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a

更改 SharePoint Online 租户中所有网站的区域设置

使用 PowerShell 脚本,我们可以在租户范围内为 SharePoint Online 中的所有网站设置区域设置。该脚本循环遍历所有站点并更改默认区域设置。只需在脚本中设置 $AdminSiteURL 和 $LocaleID 变量,并提供一次连接到 SharePoint Online 管理中心的凭据。


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#function to change Locale in regional settings of a SharePoint Online site
Function Set-SPOLocale([String]$SiteURL,[String]$LocaleID, [PSCredential]$Cred)
{ 
     Try
     {
        #Set up the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
   
        #Get Regional Settings of the Web
        $Web = $Ctx.Web
        $Ctx.Load($web)
        $Ctx.Load($Web.RegionalSettings)
        $ctx.ExecuteQuery()
 
        #Update the LocaleID of the site
        $Web.RegionalSettings.LocaleId = $LocaleID
        $Web.Update()
        $Ctx.ExecuteQuery()
 
        Write-host -f Green "Locale has been updated for "$Web.Url
 
        #Get all subsites of the web
        $Ctx.Load($Web.Webs)
        $Ctx.executeQuery() 
        #Iterate through each subsites and call the function recursively
        Foreach ($Subweb in $Web.Webs)
        {
            #Call the function to set Locale for the web
            Set-SPOLocale -SiteURL $Subweb.URL -LocaleID $LocaleID -Cred $Cred
        }
    }
    Catch [System.Exception]
    {
        Write-Host -f Red "Error:"$_.Exception.Message
    }
} 
 
#Config parameters for SharePoint Online Admin Center and Locale description
$AdminSiteURL = "https://Crescent-admin.sharepoint.com"
$LocaleID ="2057"
 
#Get credentials to connect to the SharePoint Online Admin Center
$Credentials = Get-Credential
 
#Connect to SharePoint Online Tenant Admin
Connect-SPOService -URL $AdminSiteURL -Credential $Credentials
 
#Get all Site Collections and Iterate through
Get-SPOSite -Limit ALL | ForEach-Object { 
    Set-SPOLocale -SiteURL $_.URL -LocaleID $LocaleID -Cred $Credentials
}
您可以使用公式 =TEXT(Created, “dd/mmm/yyyy”) 创建新的计算列,以不同的格式显示 SharePoint Online 中特定列表列的日期!

您还可以使用 PnP PowerShell 设置区域设置:如何使用 PowerShell 更改 SharePoint Online 中的区域设置?

结论

总之,可以通过多种方式更改 SharePoint Online 中的日期格式,包括更改网站的区域设置、更改使用 PowerShell 的日期格式以及更改租户中所有网站的日期格式。通过执行这些步骤,您可以确保 SharePoint Online 环境中的日期以满足您需求的格式显示。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯