LibCore: Add DateTime::from_timestamp(time_t)

This commit is contained in:
Andreas Kling 2020-02-11 19:48:46 +01:00
parent 2c9d94c6b9
commit 8f89cc85d1
Notes: sideshowbarker 2024-07-19 09:25:56 +09:00
2 changed files with 6 additions and 1 deletions

View file

@ -32,7 +32,11 @@ namespace Core {
DateTime DateTime::now()
{
auto timestamp = time(nullptr);
return from_timestamp(time(nullptr));
}
DateTime DateTime::from_timestamp(time_t timestamp)
{
struct tm tm;
localtime_r(&timestamp, &tm);
DateTime dt;

View file

@ -46,6 +46,7 @@ public:
String to_string() const;
static DateTime now();
static DateTime from_timestamp(time_t);
private:
time_t m_timestamp { 0 };