C++ Getting local time for saved games - date

I am making a game off Ubuntu through the terminal and one feature I would like to add is adding timestamps to the saved games.
Like the game would display "Save: (time)" and in time would be (DD/MM/YYYY HH:MM) is there a simple way to do this?

In order to get the current date you can use the command date. See man date for more format options.
$ date +'%d/%m/%y %T'
26/10/13 16:29:56
In case you would like to compute the timestamp from C++, see how to get local time and put it in a string.

Related

How to add date stamps to record journal entries

Basically I want the document to serve as some kind of journal, to record what I've done every day, so I need to add a date stamp in every entry. It should be like this:
9/14/2015
added a comma to the poem.
9/15/2015
comma deleted.
I know \date{\today} will add the date of the last compilation, but that's not what I want, and the google results are mostly about this (might be I'm search for the wrong key word).
The isodate package provides commands to switch between different date formats. You can use the following command to print a date, see the manual for details.
\printdate{09/14/2015}
The list in your example looks like a revision history, if so, take a look at the vhistory package.
Here is an example:
\documentclass{article}
\usepackage[english,num,USenglish]{isodate}
\dateinputformat{american} % mm/dd/yyyy
\usepackage{vhistory}
\begin{document}
\begin{versionhistory}
\vhEntry{1.0}{\printdate{09/14/2015}}{Olivier Ma}{added a comma to the poem.}
\vhEntry{1.1}{\printdate{09/15/2015}}{Olivier Ma}{comma deleted.}
\end{versionhistory}
\end{document}

Bulk change date to present date with ExifTool

I have a bunch of images with different create dates. I want to normalize them all to a given date (say today's date) using a batch file (Windows). Can ExifTool set dates? I only see documentation and examples for shifting dates. To shift the date to present, I would need to somehow read the date for each file, calculate the difference, and then shift. That would be ok, but I don't know how to read the create date into a variable using ExifTool.
One obstacle for me is that I don't speak Perl. I do Python, and there is pyexiv2. This allows to write the "date", but I can't see anywhere if that is just create date or all dates.
Edit
Here shows using, for example,
exiftool -AllDates='2010:08:08 15:35:33' -overwrite_original IMG_01.jpg
in Ubuntu linux, but I could not get that to work in Windows.
As a hack, I tried
exiftool -AllDates+=2015:03:02 IMG_8220.JPG
which set the dates to the time executed, probably because the shift was so completely crazy. But I'd like to have control, and, specifically be able to change YYYY:MM:DD without changing the time.
Consequently, help still appreciated.
I crossposted to the ExifTool forum, and ExifTool author Phil Harvey responded that you need to use double quotes. The single quotes from the linked blog post don't do it in Windows.
So, one would use
exiftool -AllDates="2010:08:08 15:35:33" IMG_01.jpg
I tested it and (of course) it worked.

Save programm output to file and include the actual time and date in the filename

I like to create a kind of simple error log for a python program which runs on startup (through rc.local on a raspberry). Since I like to use this for debuging my files, the error logs should include date and time in their name.
This is what I got:
sudo python myprogram.py> /home/pi/errorlogs/myprogram.txt 2>&1
So far so good - but: How can I include the actual time and date in "myprogram.txt" (so it becomes lets say "myprogramm_2014-02-10_19:45:00.txt") and is not deleted any time I reboot? I played around with .strftime("%Y-%m-%d_%H-%M"). but didnĀ“t get it to work.
Not really perfect is the fact, that I do not get a continuous output in my file - that is something I could life with since I dont need them during the run - but maybe there is a whole different approach for what I need anyway?
Just let the shell do that for you.
sudo python myprogram.py> /home/pi/errorlogs/myprogram-$(date +%Y-%m-%d_%H-%M).txt 2>&1

Batch file: Get yesterday's date in format: M_d_yyyy

How does one get yesterday's date format in a batch file?
I'd like it to look like so: M_d_yyyy
Note that if there's a single digit day and month, I'd like it to be single digits.
Example: 8_5_2013 is August 5th, 2013.
I looked around for a few days but couldn't find a solution.. any lead is much appreciated.
Nothing wrong with free 3rd party executables, but some of us are not allowed to use them on our work machines.
I have written a powerful hybrid JScript/batch utility called getTimestamp.bat that can do nearly any date and time computation on a Windows machine.
There are a great many options for specifying the base date and time, many options for adding positive or negative offsets to the date and time, many options for formatting the result, and an option to capture the result in a variable. Both input and output can be directly expressed as local time, UTC, or any time zone of your choosing. Full documentation is embedded within the script.
The utility is pure script that will run on any modern Windows machine from XP forward - no 3rd party executable required.
Assuming getTimestamp.bat is in your current directory, or better yet, somewhere within your PATH, then the following simple call will define a dt variable containing yesterday's date in M_D_YYYY format:
call getTimestamp -od -1 -f {m}_{d}_{yyyy} -r dt
Note: when I put a date in a file name, I like to use YYYY_MM_DD format because that format will sort chronologically when getting a directory listing.
I think you should get date.exe from UnxUtils.
date.exe --date="1 day ago" "+%-m_%d_%Y"
Download: http://sourceforge.net/projects/unxutils/files/unxutils/current/
Man page: http://www.ss64.com/bash/date.html
#echo off
setlocal
set magic="c:\unx\usr\local\wbin\date.exe" --date="1 day ago" "+%%-m_%%d_%%Y"
for /f %%i in ('%magic%') do set yesterdate=%%i
echo yesterdate = %yesterdate%
If you want to do it with just batch language, you'll end up with nearly 100 lines of incomprehensible batch code. UPDATE: or use dbenham's hybrid batch/JScript solution posted in the answer below, which at least uses sane Windows APIs.
See Also:
How to get current datetime on Windows command line, in a suitable format for using in a filename?

On iPhone, how do I check once per day to see if i should phone-home?

I want to check a file on the server only once each day (NSURL). And, no matter if I fetch the file or not, I do not run the function (to check for the file) again that day.
This would SEEM easy... but I forsee issues. Say I had created a directory under the mainBundle: "/Library/runOnceEachDay/". Perhaps I could write to /Library/runOnceEachDay/20100601 knowing that file would only exist if I already ran the function. If it does not exist, run the function and after the function is successful write a zero length file with the date as the filename. Then check before running that function for "mainBundle/Library/runOnceEachDay/YYYYMMDD" whereas YYYYMMDD is today's date. If that file exists, do not run.
I could run a housecleaning routine to clean that directory once/week or something. Any better ideas?
Thanks!
The logic is good. You could either do it with files as you say and "Documents" folder is a good location for such files, or you could just have a NSUserDefaults key with the date when you last phoned home.
When you start the app, get the previous phone home date/time (NSDate) from NSUserDefaults. (It won't be there the first time). This SO question (option 1) demonstrates how.
If more than 24 hours (or 7 days or whatever) has elapsed since that previous date/time (or you didn't find it there) then phone home and save the current date/time in NSUserDefaults for next startup.