I am using this rust code to get the timestamp, but the time without time zone:
use std::time::Duration;
use chrono::{DateTime, FixedOffset, Local, NaiveDateTime, TimeZone, Utc};
use diesel::sql_types::Timestamptz;
use rust_wheel::common::util::time_util::get_current_millisecond;
use tokio::time;
#[tokio::main]
async fn main() {
let trigger_time = (get_current_millisecond() - 35000)/1000;
let time_without_zone = NaiveDateTime::from_timestamp( trigger_time ,0);
}
the timestamp result is 2022-08-30 13:00:15
, the actual wanted result is: 2022-08-30 21:00:15
. Then I tried to set the timezone:
use std::time::Duration;
use chrono::{DateTime, FixedOffset, Local, NaiveDateTime, TimeZone, Utc};
use diesel::sql_types::Timestamptz;
use rust_wheel::common::util::time_util::get_current_millisecond;
use tokio::time;
#[tokio::main]
async fn main() {
let trigger_time = (get_current_millisecond() - 35000)/1000;
let time_without_zone = NaiveDateTime::from_timestamp( trigger_time ,0);
let tz_offset = FixedOffset::east(8 * 3600);
let date_time: DateTime<Local> = Local.from_local_datetime(&time_without_zone).unwrap();
print!("{}",date_time);
let dt_with_tz: DateTime<FixedOffset> = tz_offset.from_local_datetime(&time_without_zone).unwrap();
print!("{}",dt_with_tz);
}
the result is 2022-08-30 13:00:15 +08:00
. is it possible to get the timestamp with the timezone? what should I do? I mean get the timestamp format like this 2022-08-30 21:00:15
.