mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 19:57:41 +00:00
LibCore: Add DateTime::from_timestamp(time_t)
This commit is contained in:
parent
2c9d94c6b9
commit
8f89cc85d1
2 changed files with 6 additions and 1 deletions
|
@ -32,7 +32,11 @@ namespace Core {
|
||||||
|
|
||||||
DateTime DateTime::now()
|
DateTime DateTime::now()
|
||||||
{
|
{
|
||||||
auto timestamp = time(nullptr);
|
return from_timestamp(time(nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
DateTime DateTime::from_timestamp(time_t timestamp)
|
||||||
|
{
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
localtime_r(×tamp, &tm);
|
localtime_r(×tamp, &tm);
|
||||||
DateTime dt;
|
DateTime dt;
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
String to_string() const;
|
String to_string() const;
|
||||||
|
|
||||||
static DateTime now();
|
static DateTime now();
|
||||||
|
static DateTime from_timestamp(time_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
time_t m_timestamp { 0 };
|
time_t m_timestamp { 0 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue