Package com.dianxin.tori.base.utils
Class TimeUtils
java.lang.Object
com.dianxin.tori.base.utils.TimeUtils
[EN] Utility class for handling time formatting and parsing.
Primarily used for media playback features like seeking and duration display.
[VN] Lớp tiện ích để xử lý việc định dạng và phân tích thời gian.
Chủ yếu được sử dụng cho các tính năng phát phương tiện như tua (seek) và hiển thị thời lượng.
Primarily used for media playback features like seeking and duration display.
[VN] Lớp tiện ích để xử lý việc định dạng và phân tích thời gian.
Chủ yếu được sử dụng cho các tính năng phát phương tiện như tua (seek) và hiển thị thời lượng.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record[EN] Record to store the result of time parsing.
Contains the calculated duration and whether the seek is relative to current position. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatTime(long duration) [EN] Formats a duration in milliseconds into a human-readable string.
Format:HH:MM:SSorMM:SS.static longparseColonTime(String timestamp) [EN] Parses a timestamp formatted with colons.
Format accepted:HH:MM:SS,MM:SS, orSS.static TimeUtils.SeekTime[EN] Parses a seek time string into milliseconds and determines if it's relative.
Supports "colon time" (e.g.,1:20:30) or "unit time" (e.g.,1h20m).
Also detects relative seeking (starting with+or-).static longparseUnitTime(String timestr) [EN] Parses a time string formatted with units.
Examples:20m10s,1d5h,1h and 20m.
-
Constructor Details
-
TimeUtils
public TimeUtils()
-
-
Method Details
-
formatTime
[EN] Formats a duration in milliseconds into a human-readable string.
Format:HH:MM:SSorMM:SS. Returns "LIVE" if duration isLong.MAX_VALUE.
[VN] Định dạng khoảng thời gian (mili giây) thành chuỗi dễ đọc.
Định dạng:HH:MM:SShoặcMM:SS. Trả về "LIVE" nếu thời lượng làLong.MAX_VALUE.- Parameters:
duration- [EN] Time in milliseconds.
[VN] Thời gian tính bằng mili giây.- Returns:
- [EN] Formatted time string.
[VN] Chuỗi thời gian đã được định dạng.
-
parseTime
[EN] Parses a seek time string into milliseconds and determines if it's relative.
Supports "colon time" (e.g.,1:20:30) or "unit time" (e.g.,1h20m).
Also detects relative seeking (starting with+or-).
[VN] Phân tích chuỗi thời gian thành mili giây và xác định xem đó có phải là thời gian tương đối không.
Hỗ trợ "colon time" (vd:1:20:30) hoặc "unit time" (vd:1h20m).
Cũng phát hiện việc tua tương đối (bắt đầu bằng+hoặc-).- Parameters:
args- [EN] The time string to parse.
[VN] Chuỗi thời gian cần phân tích.- Returns:
- [EN] A
TimeUtils.SeekTimeobject containing milliseconds and relative flag, ornullif parsing failed.
[VN] Đối tượngTimeUtils.SeekTimechứa số mili giây và cờ tương đối, hoặcnullnếu phân tích thất bại.
-
parseColonTime
[EN] Parses a timestamp formatted with colons.
Format accepted:HH:MM:SS,MM:SS, orSS.
[VN] Phân tích chuỗi thời gian được định dạng bằng dấu hai chấm.
Các định dạng chấp nhận:HH:MM:SS,MM:SS, hoặcSS.- Parameters:
timestamp- [EN] Timestamp string (e.g., "1:30:00").
[VN] Chuỗi thời gian (vd: "1:30:00").- Returns:
- [EN] Time in milliseconds, or -1 if format is invalid.
[VN] Thời gian tính bằng mili giây, hoặc -1 nếu định dạng không hợp lệ.
-
parseUnitTime
[EN] Parses a time string formatted with units.
Examples:20m10s,1d5h,1h and 20m.
[VN] Phân tích chuỗi thời gian được định dạng kèm đơn vị.
Ví dụ:20m10s,1d5h,1h and 20m.- Parameters:
timestr- [EN] The unit time string.
[VN] Chuỗi thời gian kèm đơn vị.- Returns:
- [EN] Time in milliseconds, or -1 if parsing fails.
[VN] Thời gian tính bằng mili giây, hoặc -1 nếu phân tích thất bại.
-