1

您好,在下面的代码中想要从 LocalDateTime 中删除 T 和 Zone 。

任何人都可以帮我解决这个问题。

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
                    LocalDateTime time = LocalDateTime.now();
                        firstDayOfQuarteropp = time.with(time.getMonth().firstMonthOfQuarter())
                                .with(TemporalAdjusters.firstDayOfMonth());
                        Log.d("firstDayOfQuarteropp", String.valueOf(firstDayOfQuarteropp));
                        lastDayOfQuarteropp = firstDayOfQuarteropp.plusMonths(2)
                                .with(TemporalAdjusters.lastDayOfMonth());
                        Log.d("lastDayOfQuarteropp", String.valueOf(lastDayOfQuarteropp));
                }

实际输出:

2020-04-01T11:54:05.514

预期输出:

2020-04-01 11:54:05
4

2 回答 2

1

您需要将 DateTimeFormatter 与 LocalDateTime 一起使用

    LocalDateTime time = LocalDateTime.now(); 
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    String formatDateTime = time.format(formatter); 
    Log.d("FormattedTime", "Time: " + formatDateTime);
于 2020-06-09T06:46:32.077 回答
0

您必须格式化本地日期和时间。

public String formatedDate() {
    LocalDateTime time = LocalDateTime.now();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    return time.format(formatter);
}

并将其用作:

String dt=formatedDate();
于 2020-06-09T07:56:23.393 回答