In the time
package, when formatting a time.Time
variable, the output will use the English names for weeks and months as defined in unexported []string slices.
How to localize the string, using a different language (hopefully still using Format()
)?
Example:
fmt.Println(time.Now().Format("Mon 2 January 2006"))
Output:
Tue 28 January 2014
Desired output:
Tis 28 Januari 2014
Playground
Date and time localization is quite an important topic when it comes to developing applications and software systems in multiple languages. Date and time are written and read in different ways in different countries.
These are the basics of date and time localization in PHP. You can refer to this documentation article to get a more complete understanding of this function. To properly localize date and time in Ruby on Rails, use the localize method aliased as l.
After the appropriate locale has been set, you can easily format the time using FormatDateTime, a locale-aware function. Suppose you have retrieved the Chinese (Taiwan) locale as the primary browser locale ("zh-TW" is the default value for this locale).
TimeZone is another class for handling time zones in Java. Let’s see how to set and get time zones in Java with the TimeZone Java class. First, you need to import the time zone package as follows: Obtained the current date and time with time zone. Got the current time in different time zones by providing the actual time zone.
As you can see in time package sourcecode that values are hardcoded in source. So, basically, Go doesn't support i18n right now. i18n is on Go roadmap, its even mentioned in the faq, but there were no comments on that topic recently.
Meanwhile, you could try to use Monday package:
// Change LocaleEnUS to the locale you want to use for translation
monday.Format(time.Now(), "Mon 2 January 2006", monday.LocaleEnUS)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With