android - 如何获取特定字符串格式的日期完整时间
问题描述
我有一个 API 包含格式为“/Date(1527677209864)/”的字符串日期,如何获取要在 Android 应用程序中使用的日期和时间
解决方案
我假设 1527677209864 值是时间戳,对吗?试试这个功能:
public static String getDateAndTime(@NotNull Context context, long timestamp) {
Date date = new Date(timestamp * 1000);
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
DateFormat df = new SimpleDateFormat(getTimeFormat(context), Locale.getDefault());
return df.format(date);
}
让我知道这是否是您想要的。
推荐阅读
- sql - 如何合并具有相似值的两行?
- html - 为什么在 1440 像素宽度的屏幕上查看时,我的社交媒体页脚图标在屏幕外?
- python - 在多个空格但不是单个空格上拆分字符串
- java - 如果条件为真,我如何每秒自动运行一个按钮,直到 de 条件成立?
- github - 在 /blog 目录中安装 Gatsby
- python - 我的 base 10 或一般代码有什么问题
- java - 如何在 TextView 中压倒自动调整大小?
- javascript - Redux 商店在刷新浏览器时不刷新(清除)
- amazon-web-services - S3 存储桶策略不允许 Athena 执行查询
- php - 根据在 WooCommerce 中选择的运输方式添加费用