Reputation: 365
I am using DateTime in a Flutter project and I would like to know ifs it possible with DateTime to modify the display of the hours, for example:
by default HH: mm: ss = 12:12:12 but I would like to display 12h 12mn 12s?
my code :
String heurearchive = DateFormat('HH:mm:ss').format(DateTime.now());
Upvotes: 1
Views: 1139
Reputation: 1
DateFormat class will use as pattern what you tell to use, so if you write DateFormat('HH:mm:ss')
then it will format as HH:mm:ss
, to be as you expected try this way
DateFormat('HH\'h\' mm\'mn\' s\'s\'');
Others patterns can be found in docs
Symbol Meaning Presentation Example
------ ------- ------------ -------
G era designator (Text) AD
y year (Number) 1996
M month in year (Text & Number) July & 07
L standalone month (Text & Number) July & 07
d day in month (Number) 10
c standalone day (Number) 10
h hour in am/pm (1~12) (Number) 12
H hour in day (0~23) (Number) 0
m minute in hour (Number) 30
s second in minute (Number) 55
S fractional second (Number) 978
E day of week (Text) Tuesday
D day in year (Number) 189
a am/pm marker (Text) PM
k hour in day (1~24) (Number) 24
K hour in am/pm (0~11) (Number) 0
z time zone (Text) Pacific Standard Time
Z time zone (RFC 822) (Number) -0800
v time zone (generic) (Text) Pacific Time
Q quarter (Text) Q3
' escape for text (Delimiter) 'Date='
'' single quote (Literal) 'o''clock
Upvotes: 0
Reputation: 5423
You can achieve this with DateFormat
like this.
DateFormat("HH'h' mm'mn' ss's'")
Upvotes: 1