473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

using boost::date_time for epoch time #secs


I want to simply get the unix style epoch time
(number of secs to now from Jan 01, 1970 UTC) for
use as a timestamp to track the staleness of some
objects. So I don't care about time zones or whatever
as long as it's consistent. So I picked the epoch time
UTC getting the value I wanted, "timestamp", this way:

#include "boost/date_time/local_time/local_time.hpp"
using namespace boost::gregorian;
using namespace boost::local_time;
using namespace boost::posix_time;

namespace {
const ptime EPOCH(date(1970,1,1));
}

void
somefunc()
{
const ptime cur_time(second_clock::universal_time());
const unsigned int timestamp = (cur_time - EPOCH).total_seconds();
......
}
but I'd prefer a way that doesn't need the time_duration value (the cur_time - EPOCH)
and the EPOCH and the "total_seconds" call. I'd have thought there'd be so much
use for epoch time in seconds that there's be a prerolled function for this
in boost::date_time but I'm not seeing it. Is the above about as simple as it
gets with boost::date_time for this?

Mark
Jul 17 '07 #1
3 6237
Mark wrote:
I want to simply get the unix style epoch time
(number of secs to now from Jan 01, 1970 UTC) for
use as a timestamp to track the staleness of some
objects. So I don't care about time zones or whatever
as long as it's consistent. So I picked the epoch time
UTC getting the value I wanted, "timestamp", this way:

#include "boost/date_time/local_time/local_time.hpp"
[..]
Is the above about as
simple as it gets with boost::date_time for this?
This is not a Boost newsgroup. Please visit the Boost web site
to learn of the ways to access and of the location of their forums
where all this would be definitely on topic.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 17 '07 #2
On 2007-07-17 20:58, Mark wrote:
I want to simply get the unix style epoch time
(number of secs to now from Jan 01, 1970 UTC) for
use as a timestamp to track the staleness of some
objects. So I don't care about time zones or whatever
as long as it's consistent. So I picked the epoch time
UTC getting the value I wanted, "timestamp", this way:
What's wrong with just including time.h/ctime and using time()? While
it's not guaranteed to be the number of seconds since the epoch (could
be millisecond or something else) in the C and C++ standards it will be
on both Windows and POSIXS systems, and even if it's not, it will still
work as a timestamp (if you only want it to indicate staleness).

--
Erik Wikström
Jul 17 '07 #3
On Jul 18, 12:28 am, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-07-17 20:58, Mark wrote:
I want to simply get the unix style epoch time
(number of secs to now from Jan 01, 1970 UTC) for
use as a timestamp to track the staleness of some
objects. So I don't care about time zones or whatever
as long as it's consistent. So I picked the epoch time
UTC getting the value I wanted, "timestamp", this way:
What's wrong with just including time.h/ctime and using time()? While
it's not guaranteed to be the number of seconds since the epoch (could
be millisecond or something else) in the C and C++ standards it will be
on both Windows and POSIXS systems, and even if it's not, it will still
work as a timestamp (if you only want it to indicate staleness).
time_t isn't guaranteed to be an integral type---it could be
double. (In practice, of course, you're code probably isn't
portable everywhere, and I don't know of a system where time_t
isn't integral. It's what I'd do as well.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 19 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: deko | last post by:
I don't have access to the php.ini on my hosting provider's shared server and don't want to rely on cookies, so I'm wondering if this a reliable way to timeout a session: if (credentials are...
3
by: connieharper | last post by:
I have an ASP app that works as an online time clock. The user logs in and clocks in and out and the app records the time punches in an access 2000 database. My problem is this. I just setup a...
2
by: Jonas Granqvist | last post by:
I wonder if someone could help me with some sample code on how to make a simple application using time. How can I for instance make the program run the function "foobar()" every ten seconds? I've...
0
by: ufnuceda | last post by:
Hello everyone, I was wondering if any of you have some experience with the boost library. I am having trouble compiling code with it. Since boost is being used a lot these days I thought some...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
4
by: archana | last post by:
Hi all, I want to develop one windows service in which i want to provide some scheduling facility. What i want is to take start time frm one xml file and then at that specified start time. ...
2
by: audiophilechris | last post by:
Can anyway help me write this query? I've created a DB to help me manage delivery logistics for items I rent out. I have a table that i use to record delivery date, delivery time, pickup date,...
2
by: desktop | last post by:
I have downloaded boost throught synaptic to Ubuntu 7.04. But I don't have the folder date_time in my /usr/inculde/boost dir. How do I get date_time?
1
by: assgar | last post by:
Hi I need help. I know what I want to accomplish, but I do not know how to do it. WHAT I NEED HELP ACCOMPLISHING: How to do I insert data into a table for a date range of...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.