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