标准的TimeSpan格式,用于表示像1d、3y、30s这样的符号是什么?

huangapple go评论70阅读模式
英文:

Standard TimeSpan format for notation like 1d, 3y, 30s...?

问题

我来自.NET世界,所以我在定义时间段或时间持续期时使用TimeSpan术语。我想知道是否有任何“标准”来定义时间段,例如以下方式:

  • 1小时
  • 1秒
  • 1小时3分钟5毫秒
  • 1年3天(我知道将其转换为秒可能会有问题,但仍然)

我在InfluxDB中看到了类似的东西(https://docs.influxdata.com/flux/v0.x/data-types/basic/duration/),并且我实现了自己的版本,但这很常见,所以我在考虑是否有标准。为什么不像TimeSpan中实现的序列化方式(例如,6天:6.00:00:00)?因为这样更难阅读。

我知道这个问题类似于https://stackoverflow.com/questions/11077711/timespan-tostring-format,但我希望更简洁。

英文:

I am coming from .NET world so that why I am using TimeSpan term for defining time period or time duration. I am wondering if is any "standard" which define time period like following:

  • 1h
  • 1s
  • 1h3m5ms
  • 1y3d (i know it can already be problem here with converting it to seconds, but still)

I saw something similar in InfluxDB (https://docs.influxdata.com/flux/v0.x/data-types/basic/duration/) and I am implemented my own implementation if it, but this is so common I am wondering about standard. Why not serialization like is implemented in TimeSpan (e.g. 6 days: 6.00:00:00). Because it is harder to read.

I know this question is similar to https://stackoverflow.com/questions/11077711/timespan-tostring-format, but my wish is less verbose.

答案1

得分: 1

不清楚你具体需要什么,但如果你正在寻找任何有关时间段格式的标准,你可以使用Noda Time中的Period对象来处理ISO 8601持续时间,例如P1Y3D

如果你特别寻找你描述的格式 - 那是一种很好的人类可读的输出,但据我所知,这不是任何标准格式。

英文:

It's a little unclear what you're asking for, but if you are looking for any standard for duration formats then you can use the Period object from Noda Time to work with ISO 8601 Durations, such as P1Y3D.

If you're looking specifically for the format you described - that's some nice human-readable output, but it's not any standard I am aware of.

huangapple
  • 本文由 发表于 2023年2月10日 16:34:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75408637.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定