How to get correct timestamp in C#
Your mistake is using new DateTime(), which returns January 1, 0001 at 00:00:00.000 instead of current date and time. The correct syntax to get current date and time is DateTime.Now, so change this: to this:
Your mistake is using new DateTime(), which returns January 1, 0001 at 00:00:00.000 instead of current date and time. The correct syntax to get current date and time is DateTime.Now, so change this: to this:
note: code to be used inside a batch file. To use from command line replace %%a with %a Start the ping, force a correct line buffered output (find /v), and start a cmd process with delayed expansion enabled that will do an infinite loop reading the piped data that will be echoed to console prefixed … Read more
Understanding dmesg timestamp is pretty simple: it is time in seconds since the kernel started. So, having time of startup (uptime), you can add up the seconds and show them in whatever format you like. Or better, you could use the -T command line option of dmesg and parse the human readable format. From the man page:
Timestamps in MySQL are generally used to track changes to records, and are often updated every time the record is changed. If you want to store a specific value you should use a datetime field. If you meant that you want to decide between using a UNIX timestamp or a native MySQL datetime field, go … Read more
In order to get the current timestamp and not the time of when a fixed variable is defined, the trick is to use a function and not a variable: If you don’t like the format given by the %T specifier you can combine the other time conversion specifiers accepted by date. For GNU date, you can find the complete list of … Read more
SQL Server’s TIMESTAMP datatype has nothing to do with a date and time! It’s just a hexadecimal representation of a consecutive 8 byte integer – it’s only good for making sure a row hasn’t change since it’s been read. You can read off the hexadecimal integer or if you want a BIGINT. As an example: The result is In newer … Read more
What you missed here is timezones. Presumably you’ve five hours off UTC, so 2013-09-01T11:00:00 local and 2013-09-01T06:00:00Z are the same time. You need to read the top of the datetime docs, which explain about timezones and “naive” and “aware” objects. If your original naive datetime was UTC, the way to recover it is to use … Read more
If you have access to the C++ 11 libraries, check out the std::chrono library. You can use it to get the milliseconds since the Unix Epoch like this:
The resolution of the time() function isn’t fine grained enough to result in different values to make a different result for each call you make, i.e. the CPU is faster. You might try to insert std::this_thread::sleep_for calls to check what timing resolution fits for your needs with the hardware and OS you have at hand.
C++20 introduced a guarantee that time_since_epoch is relative to the UNIX epoch, and cppreference.com gives an example that I’ve distilled to the relevant code, and changed to units of seconds rather than hours: Using C++17 or earlier, time() is the simplest function – seconds since Epoch, which for Linux and UNIX at least would be the UNIX epoch. Linux manpage here. The … Read more