Note that I was able to subtract off the epoch in terms of hours, which implicitly converts to duration (which is seconds). I got just a little clever with this computation by writing everything in terms of M圜lock::duration so that I can more easily change duration. ![]() Based on your question, I've chosen seconds as the duration, but you can choose anything you want.įor the now() function I just call the system_clock::now() and subtract off the epoch in units of seconds. M圜lock needs nested typedefs to describe its duration, rep, period, and time_point. Typedef std::chrono::time_point time_point ĭuration_cast(system_clock::now().time_since_epoch()). ![]() Using these two facts, the rest is easy: #include As it turns out, every implementation I'm aware of (and I think I've checked them all) have this very same epoch (but this is unspecified by the C++11 standard). First I do some detective work to discover that my system_clock has an epoch of New Years 1970, neglecting leap seconds. ![]() In the example below I base the now() off of system_clock's now(). The hard part of writing this custom clock is figuring out how to write its now() function.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |