feat: add format SystemTime

This commit is contained in:
2021-10-15 15:32:56 +08:00
parent de3fb3e2b8
commit 58529b6a96
2 changed files with 12 additions and 1 deletions

View File

@@ -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"

View File

@@ -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);