在 en-US 文化中显示特定时间和日期的温度的格式

Formatting for showing temperature at a particular time and date in en-US culture

我也在网上搜索并浏览了这个 MSDN 网站,但仍然无法弄清楚以下格式的含义。有人可以举例说明吗?我正在使用 en-US culture 和最新版本的 C#。

string str = string.Format(“time: {0:t}, date: {1:dd/MM/yyyy}, temp: {2:N2}”, time,time, temperature);

更新:

例如0和1在{0:t}和{1:dd/MM/yyyy}中代表什么?

看看这个

Format(String, Object[])

还有这个

Composite Formatting

The .NET composite formatting feature takes a list of objects and a composite format string as input. A composite format string consists of fixed text intermixed with indexed placeholders, called format items, that correspond to the objects in the list. The formatting operation yields a result string that consists of the original fixed text intermixed with the string representation of the objects in the list.

第一个数字恰好对应于您在 Format

末尾解析的对象参数数组的索引
0 = time
1 = time
2 = temperature

然而,这可能对插值更有意义

$“time: {time:t}, date: {time:dd/MM/yyyy}, temp: {temperature:N2}”