473,659 Members | 2,582 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using boost::date_tim e 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::gregoria n;
using namespace boost::local_ti me;
using namespace boost::posix_ti me;

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

void
somefunc()
{
const ptime cur_time(second _clock::univers al_time());
const unsigned int timestamp = (cur_time - EPOCH).total_se conds();
......
}
but I'd prefer a way that doesn't need the time_duration value (the cur_time - EPOCH)
and the EPOCH and the "total_seco nds" 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_tim e but I'm not seeing it. Is the above about as simple as it
gets with boost::date_tim e for this?

Mark
Jul 17 '07 #1
3 6277
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_tim e 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 objektorientier ter Datenverarbeitu ng
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
3391
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 valid) { $_SESSION = time(); redirect to url }
3
2957
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 user in the central time zone and they have reported that when they use the online time clock, it saves the time as eastern time instead of central. How can I make the software know which time zone the user is in?
2
5707
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 seen programs using the time.h include file, is that the one to use? Regards, Jonas Granqvist
0
2509
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 of you might have an answer. I would greatly appreciate help with this, as I tried to search for an answer for quite some time in vain. I am getting error messages when I try to compile as soon as I put an include to the boost library in the...
17
6408
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. Note, the Windows task manager shows 2 CPUs on the Performance tab with hyper-threading is turned on. Both Python 2.3.5 and 2.4.3 (downloaded from python.org) have this problem. The operating system is MS Windows XP Professional.
4
16927
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. Which timer should i use in windows service to start particular process at user specified time.
2
1891
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, pickup time, and quantity (of items to drop off). All of the items are identical so i don't need to distinguish by type. I have 80 deliveries and 80 pickups over 7 days. I would like to generate a query that will list the total number of items out...
2
2522
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
2013
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 two or more months, where every second or third week should be able to have different events/appointments.
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8539
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.