0

Is it possible to get hour/hours minute/minutes texts in different language in .net? Does the culture info contains this kind of information? or I need to create an own library with translations..

Goal is to write it like

en: 2 hours 45 minutes
es: 2 horas 45 minutos

en: 1 hour 1 minute
es: 1 hora 1 minuto
  • 2
    C# doesn't have a built-in way to translate that. You'd either need to [do it yourself](https://stackoverflow.com/questions/2485027/timespan-to-localized-string-in-c-sharp) or use a third party library like Humanizer. – gunr2171 Apr 30 '21 at 18:02
  • @gunr2171 You should probably post that as an answer, because it is THE answer to the question. :) – dimitar.bogdanov Apr 30 '21 at 18:03
  • 3
    I'd rather mark as a duplicate. – gunr2171 Apr 30 '21 at 18:03

1 Answers1

1

While some aspects of a DateTime format may be configured with a CultureInfo (e.g. A.M., P.M. designators), the terms "minutes" and "hours" are not provided by any built-in DateTime method output (i.e. ToString). You would have to add a library or do it yourself.
See here for more about DateTimeFormat with cultures, and see here for more about culture info in general.

Connor Low
  • 5,900
  • 3
  • 31
  • 52