将单词 "Days"、"Hours"、"Minutes" 和 "Seconds" 翻译成等效的语言环境

Translate the words "Days", "Hours", "Minutes", & "Seconds" to locale equivalent

我不想将数字时间转换为不同的语言环境,但这是我所有搜索的结果。我需要将实际单词“天”、“小时”等转换为用户的语言环境等效项(例如“Jours”、“Heures”等),我还需要缩写。

这在 JavaScript 中原生可行吗?

您可以使用 Intl.DateTimeFormat():

The Intl.DateTimeFormat() constructor for objects that enable language-sensitive date and time formatting.

一个例子:

var date = new Date();
let o = new Intl.DateTimeFormat("fr-FR" , {
    timeStyle: "full",
    dateStyle: "full"
});
console.log(o.format(date));