android - 使用数据绑定(bind)时从 getTimeInMillis 获取日期

我有一个 timeInMillis 值,我知道我可以从中得到一个 Date 类似的东西;

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); 
String dateString = formatter.format(new Date(dateInMillis)));

我正在使用 DataBinding 来填充 RecyclerView。我也知道在使用 DataBinding 时可以操作字符串;

android:text='@{String.format("%.1f", example.double)}'

但是,我无法确定如何使用 timeInMillis 值中的格式化 Date 填充 TextView

最佳答案

我认为将格式放入资源中是最好的方法:

<string name="format">%1$td/%1$tm/%1$tY</string>

您可以像这样将值绑定(bind)到资源:

<TextView ... android:text="@{@string/format(model.date)}" />

https://stackoverflow.com/questions/42596831/

相关文章:

Java - 土耳其语或其他月份的日期格式

javascript - 使用 jQuery 在输入框中显示一个小数点后 2 位的值,同时保持更高的

mysql - 这是什么时间格式? (不是 UNIX,不是 UTC,什么都没有)

java - 意外的 java SimpleDateFormat 解析异常

c# - 格式化难读的 try..catch..finally block ?

c - C中孤花括号代码块的含义

Python - 轻松将文本文件内容转换为字典值/键

c# - 格式化 C# 输出

haskell - 新线 haskell

jsp - 如何将变量设置为小数点后 2 位