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

View File

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