Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9027803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:50:02+00:00 2026-06-16T06:50:02+00:00

Is there cross-platform solution to get seconds since epoch, for windows i use long

  • 0

Is there cross-platform solution to get seconds since epoch, for windows i use

long long NativesGetTimeInSeconds()
{
    return time (NULL);
}

But how to get on Linux?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:50:04+00:00Added an answer on June 16, 2026 at 6:50 am

    You’re already using it: std::time(0) (don’t forget to #include <ctime>). However, whether std::time actually returns the time since epoch isn’t specified in the standard (C11, referenced by the C++ standard):

    7.27.2.4 The time function

    Synopsis

    #include <time.h>
    time_t time(time_t *timer);
    

    Description

    The time function determines the current calendar time. The encoding of the value is unspecified. [emphasis mine]

    For C++, C++11 and later provide time_since_epoch. However, before C++20 the epoch of std::chrono::system_clock was unspecified and therefore possibly non-portable in previous standards.

    Still, on Linux the std::chrono::system_clock will usually use Unix Time even in C++11, C++14 and C++17, so you can use the following code:

    #include <chrono>
    
    // make the decltype slightly easier to the eye
    using seconds_t = std::chrono::seconds;
    
    // return the same type as seconds.count() below does.
    // note: C++14 makes this a lot easier.
    decltype(seconds_t().count()) get_seconds_since_epoch()
    {
        // get the current time
        const auto now     = std::chrono::system_clock::now();
    
        // transform the time into a duration since the epoch
        const auto epoch   = now.time_since_epoch();
    
        // cast the duration into seconds
        const auto seconds = std::chrono::duration_cast<std::chrono::seconds>(epoch);
        
        // return the number of seconds
        return seconds.count();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are so many cross platform libraries that I am kinda lost to get
Are there any high-level, cross-platform, and abstracted (simple to use) widget toolkits for C
We need a cross platform solution for compressing files. Our server runs on Windows
I heard that there is no pure, cross-platform solution. But maybe there are three
Is there a cross-platform network library for the iPhone? Is ACE available for the
Is there anyway to create a desktop icon (cross platform/browser) from a linked image
I'm currently developing a cross-platform C application. Is there any compiler macro which is
I am writing a program that is cross platform. There are a few spots
Is there a way to get an image from a usb scanner (on Windows
I am implementing a cross platform scripting language for our product. There is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.