PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 11, 2022

[FIXED] How do I get a SystemTime from a human-readable date format in a cross-platform way? (Rust)

 September 11, 2022     cross-platform, datetime, rust     No comments   

Issue

How would I convert a human readable time (in any format, such as Tue, 1 Jul 2003 10:52:37 +0200) into a SystemTime, in a cross-platform way? I know about chrono::DateTime::from_rfc2822(), but I've been searching for quite a while and I can't find a way to convert a DateTime into a SystemTime. This conversion also needs to be cross-platform, so I can't use the platform-specific epochs (such as UNIX_EPOCH).

Does anyone have any advice or ideas on how to do this?


Solution

There is a conversion available for DateTime<Tz> to SystemTime, so you just need to call .into():

let system_time: SystemTime = DateTime::parse_from_rfc2822("Tue, 1 Jul 2003 10:52:37 +0200").unwrap().into();

Playground



Answered By - kmdreko
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing