Is there any better method of displaying wall clock time except using walltimestamp variable? - dtrace

I want to print the time when a probe is fired. After checking the Dtrace documents, I find the built-in variable: walltimestamp. And the Dtrace script likes this:
pid$1::func:entry
{
trace(walltimestamp);
}
But the walltimestamp is "The current number of nanoseconds since 00:00 Universal Coordinated Time, January 1, 1970.", so the output likes "1389583988106535481".
I think this isn't easy for user to understand and want the output likes "Mon Jan 13 00:00:00 2014". I have searched whether Dtrace provide functions like ctime in C programming language, but nothing found.
Does anyone need to implement a function like ctime by himself? Or Is there any better method to display the time?

Use printf():
# dtrace -qn 'BEGIN {printf("%Y\n", walltimestamp); exit(0)}'
2014 Jan 13 08:37:56
#

Related

Question about different datetime format, really confusing

This question is probably better to explain with an example date, for instance the datetime now (London time): 21/08/2020 11:34 am
I'm confused about the time with 'ET' and also UTC format, and ISO format, is EDT same as ET?
Why so many different format and they are sooooo confusing. Can someone explain in a simple way, the information online is not very easy to understand unless I didn't find the right documentation.
The reason I want it to convert ET to UTC is because AWS cron job only take this format (please correct me if I'm wrong) Thanks in advance.
Yeah, you are right. AWS Cron job takes only UTC timestamp.
UTC and GMT are different ways of tracking time. EDT(ET) both are same. You can read about ISO vs UTC here, nicely explained here.
To covert one timestamp to other one, you can use this.

Does _finddata_t structure return time_write as system time or it is influenced by session timezone?

I am referring the documentation of _filefirst() and _findnext() APIs here
These APIs return file information in a _finddata_t structure. I need to access file modification time from time_write element. Though documentation says that
time is stored in UTC format (It is a times stamp). Documentation doesn't clarify if this time represents local time or UTC time. It seems to me that time_write doesn't return the UTC time instead its value is influenced by the system time zone settings.
My Question is - Does time_write returns local time represented in the UTC timestamps ?
Edit1
Here I explain what actually I am trying to understand. My system is in IST timezone. Now, there is a file emp10.ibd for which windows shows
Date Created - 10/21/2016 10:51 AM
Date Modified -10/21/2016 10:51 AM
I used epoch converter to find out the the epoch timestamp for which it turn out to be as following -
Now if I retrieve the time_write element from _finddata_t structure which has been returned by _findnext() for the same file i.e. emp10.ibd. I expect the returned timestamp should be close to
Epoch timestamp 1477027260 as shown in the image above.
But I get the time_write as 1477043509
If I again use epoch converter I get the following
I am trying to understand why there is 4:30 Hours of time difference in GMT in both images shared above? IMO timestamp should have been almost same. What obvious I am missing here ?
Edit2
For those folks who were asking for sample code. Here I paste link of another post which I had asked a year ago for the same reason but scenario was little different, There I was referring to _stati64 struct. I didn't troubleshoot the problem further at that time. By now it is pretty clear that
_finddata_t and _stati64 APIs are affected by _tzset environment variable as Harry mentioned in this post while FILETIME struct is not.
Local time is UTC plus a geographical offset plus potentially a seasonal offset. A UTC timestamp has no such offsets.
In this particular case, the exact format is seconds since1970-01-01T00:00:00Z i.e. January 1st, 1970, at midnight UTC.
To troubleshoot further, next I used GetFileTime API to retrieve the
the file modification time in FILETIME struct and converted the time into UTC timestamp. I got the time according the time set on my computer. I was expecting the same.
At this point I started investigating the way we execute our program through a perl script. I found that perl script was setting the timezone to GMT-1.
Since my computer was in timezone GMT+5:30, therefore I used to get resultant +04:30 hrs of difference as mentioned in the original post.
Therefore I would like to sum up my experience as - the outcome of _finddata_t strcut is affected by the timezone set in the session but the outcome of FILETIME struct is not affected by the time zone set in the session, instead it is the time according the system timezone. Since I was retrieving one time using FILETIME struct and another using _finddata_t strcut that was causing the problem. Took me ~48Hrs to find out this interesting observation.
Why does that happen? Perhaps the answer is provided by Harry in the comment section.I am pasting the same here as it is -
changing the timezone in Perl is probably causing the TZ environment variable to be set, which affects the C runtime library as per the documentation for _tzset. It isn't a per-session setting, at least not in the way Windows uses the word "session"."
Edit1
From File Times, I read the following -
FindFirstFile retrieves the local time from the FAT file system and converts it to UTC by using the current settings for the time zone and daylight saving time.
Though I was using the NTFS file system but I believe it uses the same mechanism i.e. retrieve the local time from file system and converts it to UTC by using current settings. That's the reason I noticed the difference.

Print current month as calendar using current system date C++

First time poster so excuse me if I make any sort of mistake.
I am fairly new to the whole programming in C++ but I was wondering if it is possible to print out a calendar of a certain month (the current one) e.g. today it is June 2015 so I want to print out the monthly calendar of June 2015 in C++
If anyone has any suggestion how to make this possible that would be extremely helpful. I know how to post the current month with user input yet I want my program to look at the system date.
Thanks in advance.
Use time(0) to get a time_t that is also somehow the number of seconds since xxxoopsxxxxx => epoch: Wed Dec 31 19:00:00 1969, so 1/1/1970
time_t linearTime = time(0);
Use localtime_r to convert the linearTime to
struct tm timeinfo = *localtime_r(&linearTime, &timeinfo);
Use struct tm to decode broken-down-time (in Linux, at /usr/include/time.h) and produce your calendar as you want.
Have fun.
Edit 2
Looked into chrono. Figured out how to measure duration in us.
BUT, the following chrono stuff is suspiciously similar to previous stuff.
std::time_t t0 = std::time(nullptr);
std::tm* localtime(const std::time_t* t0); // std::tm has the fields you expect
// convenient to text
std::cout << std::asctime(std::localtime(&t0)); // prints the calendar info for 'now'
I suspect not much different at all.
edit 3
I have doubts. I think the previous suspiciously familiar bit came from ctime, not chrono. So I plan digging around in chrono some more.

C++ and Windows: Is SYSTEMTIME always based on the Gregorian calendar?

I have a SYSTEMTIME struct. This struct may either contain a UTC time or a local time that was returned from a Windows API function at some prior point and time.
In C++ I am calculating the day of the year based on the SYSTEMTIME that a function returns. In other words how many days since Jan 1. In order to do that I need to be mindful of the extra day during leap years, Feburary 29. That's all easy enough if I knew that the SYSTEMTIME is always based on the gregorian calendar.
If a user in a foreign country uses some other calendar system wouldn't I have a problem calculating the day of the year? I can't seem to do this on my machine to test the theory, and I don't even know if it's plausible. Any Microsoft experts that can help me out here?
Maybe a better question would be is there already a Windows API function that calculates the day of the year based on a SYSTEMTIME? I can't find one.
The closest thing I could find searching is this javascript question, which is interesting but I think very different from what I'm asking. I won't see any replies to this question until tomorrow (Monday) so if there are any follow up questions I will answer them then.
Thanks!
edit: I found this article but it still doesn't answer the question:
OS level support for non-Gregorian calendars? - Sorting it all Out - Site Home - MSDN Blogs
In looking at SYSTEMTIME on MSDN, it says:
Retrieves the current system date and time. The system time is expressed in Coordinated Universal Time (UTC).
It seems that regardless, SYSTEMTIME works in the Gregorian calendar.
Best of luck, I hope that I was of help.

Convert GMT time local time in XSLT

How to convert GMT time to local time ( MDT or MST ) automatically.
I got this below working but i need a condition which determines utc -6 or utc -7 based on dates.
<xsl:value-of select="xs:dateTime($docdate) + xs:dayTimeDuration('-PT7H')"/>
Thanks
Hari
You might look at the function adjust-time-to-timezone($arg as xs:time?), which adjusts the time given in $arg to the implicit timezone given in the dynamic context. There are no guarantees, but in many implementations that is likely to be the timezone set in the operating system environment.
For example, if I evaluate the expression
adjust-time-to-timezone( xs:time('20:45:00.0+01:00'))
my system (current set to 7 hours west of UTC) returns the value
12:45:00-07:00
You can use a script, for example a javascript using javascript dates.