Skip to content

Improvement [3463] Improved Date formatter - #3466

Merged
LearningGp merged 4 commits into
alibaba:1.8from
manojks1999:improved_date_formatter
Sep 16, 2025
Merged

LearningGp merged 4 commits into
alibaba:1.8from
manojks1999:improved_date_formatter

Conversation

@manojks1999

Copy link
Copy Markdown
Contributor

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

*/
public String toFatString() {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DateTimeFormatter 应该改成静态成员变量
private static DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done made it as private static variable


LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
sb.append(dateTime.format(formatter)).append("|");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dateTime.format(formatter)改成 df.format(dataTime), 因为dateTime.format(formatter)内部就是调用的df.format(dataTime)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brucelwl made a changes.

@LearningGp
LearningGp requested a review from Copilot September 15, 2025 12:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@LearningGp LearningGp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LearningGp
LearningGp merged commit 4a41981 into alibaba:1.8 Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MetricNode#toFatString 时间转换影响性能

4 participants