在三星设备上无法使用DateTimeFormatter.format(LocalDateTime)方法,因为三星设备默认情况下对于日期时间格式具有局限性。为了解决这个问题,可以使用SimpleDateFormat类来转换时间格式,如下所示:
// 创建SimpleDateFormat实例
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
// 获取当前时间
long currentTime = System.currentTimeMillis();
// 转换为字符串
String dateString = dateFormat.format(new Date(currentTime));
通过这种方法,就可以将时间转换为指定的格式。注意,要指定正确的时间格式并使用正确的Locale来进行本地化。