time

DateTime.UtcNow.Ticks sometimes jumps a remarkable amount

In a tightly looped test application that prints out the value of DateTime.UtcNow.Ticks, I notice that the value will jump a remarkable amount once every hour or so. Look closely at the following sample data: 1:52:14.312 PM - 633614215343125000 1:52:14.359 PM - 633614215343593750 1:52:14.421 PM - 633614215344218750 1:52:14.468 PM - 633...

Displaying time and timezone information to the user (what, not how)

(This is a question about the UI rather than the technology required to do it) What is the clearest way to display a time for events occurring in different timezones to a user? Does your "average" user understand UTC and timezones? We capture the local time and UTC offset and store it in the database (SQL 2008 DateTimeOffset) for event...

How do I calculate the week number given a date?

If I have a date, how do I calculate the week number for that date within that year? For example, in 2008, January 1st to January 6th are in week 1 and January 7th to the 13th are in week 2, so if my date was January 10th 2008, my week number would be 2. An algorithm would be great to get me started and sample code would also help - I'...

Convert to/from DateTime and Time in Ruby

How do you convert between a DateTime and a Time object in Ruby? ...

How does one - without inheritance - override a class method and call the original from within the new method?

I found one source which successfully overrode Time.strftime like this: class Time alias :old_strftime :strftime def strftime #do something old_strftime end end The trouble is, strftime is an instance method. I need to override Time.now - a class method - in such away that any caller gets my new method, while the new me...

Is there a way to define the timezone for an application in ASP.NET?

Hi, Is there a way to define the timezone for an application in ASP.NET such that all times read from/compared to current server time are implicitly converted, or do I need to put in conversion statements as each and every DateTime.Now call? ...

Time difference in C++

Hi guys, Does anyone know how to calculate time difference in C++ in miliseconds? I used difftime (time.h) but it's not enough precision for what I'm trying to measure. Thanks, in advance. Alejo ...

are there any commands that are usually used for comparing time in bash shell script?

this was for an old computer class project which I am over with and now am wondering if there was a better way of doing things . we used to program an appointment.sh program where I solved the comparing time using an algorithm which converts time to a certain number you can compare today and tomorrow and of course what happens is it c...

Ruby on Rails: Why do I get timezones munged when I write a time to the DB, then read it back?

I have config.time_zone in environment.rb set to "UTC", and my mySQL server returns the current time in my local time zone when I issue "select now();" and in utc when I ask for "select utc_timestamp;" I'm running rails 2.1.2, the mysql gem 2.7.3, activerecord gem 2.1.2, and mysql --version returns "Ver 14.12 Distrib 5.0.27 for Win32 (i...

How to generate running time graph for my Java program

Hi I want to generate running time graphs on my java program. Is there any program which makes it? ...

Calculate time period using C

How would I calculate a time period between 2 dates using C (any library, etc.). For example the program would take two (local) dates and would spit out the period duration between them. For example startDate = oct-9-1976 and endDate = oct-9-2008 would show a duration of 32 years OR startDate = oct-9-1976 and endDate = dec-9-2008 would s...

How do I combine a java.util.Date object with a java.sql.Time object?

I'm pulling back a Date and a Time from a database. They are stored in separate fields, but I would like to combine them into a java.util.Date object that reflects the date/time appropriately. Here is my original approach, but it is flawed. I always end up with a Date/Time that is 6 hours off what it should be. I think this is because t...

Client Side MD5 Hash with Time Salt

I want to salt a hashed username and password (submitted via http POST) in JS on the client-side with a higher-order time value (< 1 minute resolution) to avoid sending the username and password hash as a constant value that could be used for a log-in attempt via POST fabrication by an unauthorized user (i.e. a sniffer). This will impos...

Rails ActiveSupport Time Parsing?

Rails' ActiveSupport module extends the builtin ruby Time class with a number of methods. Notably, there is the to_formatted_s method, which lets you write Time.now.to_formatted_s(:db) to get a string in Database format, rather than having to write ugly strftime format-strings everywhere. My question is, is there a way to go backwards?...

iPhone: How to get current milliseconds?

What is the best way to get the current system time milliseconds? ...

How to get time difference in minutes in PHP

How to calculate minute difference between two date-times in PHP? ...

What do you tell your customers when they ask: "How long will it take?"

I charge my clients by the hour when building them websites. It's the only reasonable way for me to do it without either ripping them off, or ripping myself off. They always ask: "How many hours do you think it will take?" and I usually don't know what to tell them without stressing myself out by putting myself on a time line. What do yo...

System.currentTimeMillis() vs. new Date() vs. Calendar.getInstance().getTime()

In Java, what are the performance and resource implications of using System.currentTimeMillis() vs. new Date() vs. Calendar.getInstance().getTime() As I understand it, System.currentTimeMillis() is the most efficient. However, in most applications, that long value would need to be converted to a Date or some similar object to ...

C# DateTime: What "date" to use when i'm using just the "time"?

i'm using a DateTime in C# to display times. What date portion does everyone use when constructing a time? e.g. the following is not valid: //4:37:58 PM DateTime time = new DateTime(0, 0, 0, 16, 47, 58); because there is no zero-th month or zero-th day. Do i use COM's zero date? //4:37:58 PM DateTime time = new DateTime(1899, 12, 3...

How do I get the time a file was last modified in Python?

Assuming the file exists (using os.path.exists(filename) to first make sure that it does), how do I display the time a file was last modified? This is on Linux if that makes any difference. ...