Giter VIP home page Giter VIP logo

Comments (5)

 avatar commented on August 26, 2024 3

Also affected on windows VS2015, I get time stamps as [1970-01-02 06:01:03.451556]. system_clock works as expected [2017-02-02 12:22:14.434341].

If high_resolution_clock is important for time stamps, may be offset can be used?

    uint64_t timestamp_now()
    {
	    static auto hrc_offset = std::chrono::system_clock::now().time_since_epoch() - std::chrono::high_resolution_clock::now().time_since_epoch();
	    return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch() + hrc_offset).count();
    }

from nanolog.

Iyengar111 avatar Iyengar111 commented on August 26, 2024

Hi,

Can you give me a reference where it mentions steady_clock epoch is not Jan 1, 1970.

Thanks.

from nanolog.

BTNC avatar BTNC commented on August 26, 2024

Search steady_clock from google could result lots of discussions about system_clock, steady_clock, etc. Below are 2 of those references: cppreference,stackoverflow

from nanolog.

sandym avatar sandym commented on August 26, 2024

With libc++, high_resolution_clock epoch is the last boot time.

from nanolog.

alanthie avatar alanthie commented on August 26, 2024
uint64_t timestamp_now()
{
  return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}

void format_timestamp(std::ostream & os, uint64_t timestamp)
{
  auto usecs = std::chrono::microseconds(timestamp);
  auto secs = std::chrono::duration_cast<std::chrono::seconds> (usecs);
  usecs -= secs;
  std::time_t time_t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::time_point{ secs });

  os << '[' << std::put_time(std::localtime(&time_t), "%Y-%m-%d %X");
  os << "." << usecs.count() << ']';
}

[2018-05-01 21:17:45.272498][INFO][20072][c:\work\nanolog\main.cpp:main:20] Sample NanoLog: 0
[2018-05-01 21:17:45.272508][INFO][20072][c:\work\nanolog\main.cpp:main:20] Sample NanoLog: 1
[2018-05-01 21:17:45.272513][INFO][20072][c:\work\nanolog\main.cpp:main:20] Sample NanoLog: 2
[2018-05-01 21:17:45.272517][INFO][20072][c:\work\nanolog\main.cpp:main:20] Sample NanoLog: 3
[2018-05-01 21:17:45.272522][INFO][20072][c:\work\nanolog\main.cpp:main:20] Sample NanoLog: 4

from nanolog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.