I am writing a python script which mainly involves decoration of console output.
I have some value called expiration_time which is in milliseconds. When I display expiration_time on console it is hard to find how much time exactly left to expire. User needs to do some calculation to know how much time is left.
So I decided to print epoch time instead. I want to do something like this:
epoch_time_at_which_expiration_will_happen = current_epoch_time + expiration_time_in_milliseconds
I want to output epoch_time_at_which_expiration_will_happen. How can I do it?
Not really sure what you are trying to output, the time at which expiration happens or the time until the expiration?
Either way, I would use a datetime object instead of the epoch time and convert the milliseconds to microseconds. The datetime objects allow you to do the math you want and to display the output formatted nicely.
https://docs.python.org/2/library/datetime.html
What's the correct way to get the Unix timestamp in Go? I thought it would be time.Now().Unix() but it's clearly not.
http://play.golang.org/p/KoJADUDxOS
So time.Now().Unix() tells me the unix timestamp is 1257894000 whereas my browser tells me it is 1398351437. Also www.unixtimestamp.de tells me it is 1398351704 which is what I would expect. Why is the one coming from Go so far off? I get the same results on my local machine btw.
What am I missing?
UPDATE
Ok, turns out it was really only an issue on play.golang.org. I thought I tested it locally as well but I had another look now and yes on my local machine everything is correct.
Unix() does produce a Unix timestap: The number of seconds since the epoch.
I think the documentation http://golang.org/pkg/time/#Time.Unix is pretty clear here.
Maybe you are not interested in a Unix timestamp but some human readable time? In that case use Format(): http://golang.org/pkg/time/#Time.Format
And: The playground has only synthetic time. Absolute values on the playground do not correspond to UTC.
I have a page displayed in classic ASP. 90% of the time the dates on the page show on users' machines as MM/DD/YY - same as the international settings in the registry for short date format. About 10% of the time this gets switched around and is presented as DD/MM/YY. After a restart of the machine MM/DD/YY is displayed again.
I assume some process has run which is changing the default date format. Any ideas on what I can do to a.) diagnose which program may be changing the date format and b.) how to ensure the default format is in place before loading my page?
Thanks in advance for your help.
This has to do with the complicated way that IIS and Windows are trying to figure out the "default" way to specify the date since you haven't explicitly set it in the code.
You can read more here on MSFT about the date format randomly changing.
You said a reboot fixes it, which to me implies someone is logging on to the machine and that person has a different date format. The reboot kicks them off, and it reverts back.
The workaround is just to set your date format explicitly in the code, but that's a different question.
For an assignment I need to determine the creation time of a random file. As far as I know, Unix does not store the creation time (in contrast to *-BSD). I think I've read somewhere that you should ask for the modification time instead but I don't know where and asking Google doesn't give me a non-ambigious answser either.
Any ideas?
You cannot get the creation time of files in this context. That makes the assignment easy enough: it reasonably cannot be completed.
If someone is talking about creation time in Unix, they are confused. Modification time is completely different from creation time (obviously).
For the record, there are exactly three timestamps in Unix files: ctime, atime and mtime.
Try stat. It will give you all the times associated with a file.
stat filename
To get just the modification date and time:
stat --format=%y filename
Or in seconds since the Epoch:
stat --format=%Y filename
I have a program that uses save files. It needs to load the newest save file, but fall back on the next newest if that one is unavailable or corrupted. Can I use the windows file creation timestamp to tell the order of when they were created, or is this unreliable? I am asking because the "changed" timestamps seem unreliable. I can embed the creation time/date in the name if I have to, but it would be easier to use the file system dates if possible.
If you have a directory full of arbitrary and randomly named files and 'time' is the only factor, it may be more pointful to establish a filename that matches the timestamp to eliminate need for using tools to view it.
2008_12_31_24_60_60_1000
Would be my recommendation for a flatfile system.
Sometimes if you have a lot of files, you may want to group them, ie:
2008/
2008/12/
2008/12/31
2008/12/31/00-12/
2008/12/31/13-24/24_60_60_1000
or something larger
2008/
2008/12_31/
etc etc etc.
( Moreover, if you're not embedding the time, what is your other distinguishing characteritics, you cant have a null file name, and creating monotonically increasing sequences is way harder ? need info )
What do you mean by "reliable"? When you create a file, it gets a timestamp, and that works. Now, the resolution of that timestamp is not necessarily high -- on FAT16 it was 2 seconds, I think. On FAT32 and NTFS it probably is 1 second. So if you are saving your files at a rate of less then one per second, you should be good there. Keep in mind, that user can change the timestamp value arbitrarily. If you are concerned about that, you'll have to embed the timestamp into the file itself (although in my opinion that would be ovekill)
Of course if the user of the machine is an administrator, they can set the current time to whatever they want it to be, and the system will happily timestamp files with that time.
So it all depends on what you're trying to do with the information.
Windows timestamps are in UTC. So if your timezone changes (ie. when daylight savings starts or ends) the timestamp will move forward/back an hour. Apart from that, and the accuracy of about 2 seconds, there is no reason to think that the timestamps are invalid, and its certainly ok to use them. But I think its bad practice, when you can simply put the timestamp in the name, or in the file itself even.
What if the system time is changed for some reason? It seems handy, but perhaps some other version number counting up would be better.
Added: A similar question, but with databases, here.
I faced some issues with created time of a file after deletion and recreation under same name.
Something similar to this comment in GetFileInfoEx docs
Problem getting correct Creation Time after file was recreated
I tried to use GetFileAttributesEx and then get ftCreationTime field of
the resulting WIN32_FILE_ATTRIBUTE_DATA structure. It works just fine
at first, but after I delete file and recreate again, it keeps giving
me the original already incorrect value until I restart the process
again. The same problem happens for FindFirstFile API, as well. I use
Window 2003.
this is said to be related to something called tunnelling
try usining this when you want to rename the file
Path.Combine(ArchivedPath, currentDate + " " + fileInfo.Name))