feat: add format SystemTime
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "simpledateformat"
|
name = "simpledateformat"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "SimpleDateFormat.java style like date format"
|
description = "SimpleDateFormat.java style like date format"
|
||||||
|
|||||||
11
src/lib.rs
11
src/lib.rs
@@ -8,6 +8,7 @@ use std::{
|
|||||||
str::Chars,
|
str::Chars,
|
||||||
iter::Peekable,
|
iter::Peekable,
|
||||||
};
|
};
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
quick_error! {
|
quick_error! {
|
||||||
/// Format parse error
|
/// Format parse error
|
||||||
@@ -114,6 +115,16 @@ impl SimpleDateFormat {
|
|||||||
self.format(&Utc::now())
|
self.format(&Utc::now())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn format_utc(&self, time: SystemTime) -> String {
|
||||||
|
let date_time: DateTime<Utc> = time.into();
|
||||||
|
self.format(&date_time)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn format_local(&self, time: SystemTime) -> String {
|
||||||
|
let date_time: DateTime<Local> = time.into();
|
||||||
|
self.format(&date_time)
|
||||||
|
}
|
||||||
|
|
||||||
// Format date
|
// Format date
|
||||||
/// ```ignore
|
/// ```ignore
|
||||||
/// let t = Utc.timestamp_millis(1590816448678);
|
/// let t = Utc.timestamp_millis(1590816448678);
|
||||||
|
|||||||
Reference in New Issue
Block a user