Repository navigation
Improvement [3463] Improved Date formatter - #3466
Conversation
| */ | ||
| public String toFatString() { | ||
| DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
| DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
There was a problem hiding this comment.
DateTimeFormatter 应该改成静态成员变量
private static DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
There was a problem hiding this comment.
Done made it as private static variable
|
|
||
| LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()); | ||
| sb.append(dateTime.format(formatter)).append("|"); | ||
|
|
There was a problem hiding this comment.
dateTime.format(formatter)改成 df.format(dataTime), 因为dateTime.format(formatter)内部就是调用的df.format(dataTime)
There was a problem hiding this comment.
Pull Request Overview
This PR improves the date formatting implementation in the MetricNode class by migrating from the legacy SimpleDateFormat to the modern DateTimeFormatter API. The change addresses issue #3463 by replacing thread-unsafe SimpleDateFormat with the thread-safe and more efficient java.time API.
Key changes:
- Replaced SimpleDateFormat with DateTimeFormatter for better thread safety and performance
- Updated imports to use java.time package instead of java.text
- Moved DateTimeFormatter instance to a static field to avoid repeated object creation
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Describe what this PR does / why we need it
Improvement for date formatter
Does this pull request fix one issue?
#3463 3463
Fixes #3463 3463
Describe how you did it
Changed to DateTimeFormatter from Java
Describe how to verify it
Special notes for reviews