- Dart:Scalable Application Development
- Davy Mitchell Sergey Akopkokhyants Ivo Balbaert
- 251字
- 2021-07-09 18:56:20
Working with dates
The ISO 8601 standard for dates is 'Year Month Day', and naturally, no country in the world uses this standard day to day! A typical variation is to have the month or day first, and then the separator character is used between digits in shorthand.
The intl
package can help provide the appropriate format and translations for each language. Translation strings are required too as the name of the day or month may be required.
Date handling is implemented in the SlideShowApp
class:
import 'package:intl/date_symbol_data_local.dart';
A field is used to keep a reference to the active DateFormat
object:
DateFormat slideDateFormatter;
We will consider how this formatter is initialized and kept up to date with the changes made to the users language.
Formatting for the locale
The locale for the date formatter will need to be updated whenever the interface language is changed:
qs("#interfaceLang").onChange.listen((e){ var lang = qs("#interfaceLang").value; setInterfaceLang(lang); langInterface = lang; initDefaultDate(); });
When a locale has been requested, the appropriate DateFormat
object needs to be created:
initDefaultDate() { initializeDateFormatting(langInterface, null).then((d) { slideDateFormatter = new DateFormat.yMMMMEEEEd(langInterface); }); }
Once this is in place, it is possible to change the interface language using the combo box and get a date in the correct format and language.

As a final thought on this topic, most web applications are not nearly as dynamic in their choice of language. Typically, an interface language selection is a per user configuration option that is set up for each session when the user logs in.
- iOS Game Programming Cookbook
- Mastering JavaScript Object-Oriented Programming
- Python for Secret Agents:Volume II
- Rust Cookbook
- PLC編程及應(yīng)用實戰(zhàn)
- Python深度學(xué)習(xí):基于TensorFlow
- PHP+Ajax+jQuery網(wǎng)站開發(fā)項目式教程
- 零基礎(chǔ)學(xué)HTML+CSS第2版
- Python機器學(xué)習(xí)與量化投資
- Unity虛擬現(xiàn)實開發(fā)圣典
- 計算機應(yīng)用基礎(chǔ)
- 數(shù)據(jù)科學(xué)之編程技術(shù):使用R進行數(shù)據(jù)清理、分析與可視化
- 精通Django 3 Web開發(fā)
- 軟件測試(第2版)
- WooCommerce Cookbook