Questions tagged [systemtime]

In computer science and computer programming, system time represents a computer system's notion of the passing of time.

171 questions
212
votes
24 answers

Unit Testing: DateTime.Now

I have some unit tests that expects the 'current time' to be different than DateTime.Now and I don't want to change the computer's time, obviously. What's the best strategy to achieve this?
Pedro
  • 11,514
  • 5
  • 27
  • 40
167
votes
12 answers

Override Java System.currentTimeMillis for testing time sensitive code

Is there a way, either in code or with JVM arguments, to override the current time, as presented via System.currentTimeMillis, other than manually changing the system clock on the host machine? A little background: We have a system that runs a…
Mike Clark
  • 11,769
  • 6
  • 39
  • 43
98
votes
11 answers

How can I mock java.time.LocalDate.now()

In my test case, I need test time sensitive method, in that method we're using java 8 class LocalDate, it is not Joda. What can I do to change time, when I'm running test
Neil
  • 2,714
  • 11
  • 29
  • 45
21
votes
9 answers

How can I set the System Time in Java?

Is it possible to change the System Time in Java? It should run under Windows and Linux. I've tried it with the Runtime Class in but there is a problem with the permissions. This is my code: String cmd="date -s…
joen
  • 634
  • 2
  • 5
  • 14
18
votes
5 answers

How to prevent usage of expired license through system clock tampering?

I am currently working on a license manager using java, I will be specifying a start and end date for my application so I can force a licensed user to re-license the program after a certain amount of time. But the problem I am facing is that any one…
Lalchand
  • 7,627
  • 26
  • 67
  • 79
16
votes
3 answers

Getting getrusage() to measure system time in C

I would like to measure the system time it takes to execute some code. To do this I know I would sandwich said code between two calls to getrusage(), but I get some unexpected results... #include #include #include…
Stout Joe
  • 324
  • 2
  • 4
  • 14
14
votes
3 answers

difference between two SYSTEMTIME variable

I want to get difference between two SYSTEMTIME variable. I saw someone asked this question here before, but he was told to convert both SYSTEMTIME structures to FILETIME.. Is there another way to get the difference? SYSTEMTIME…
kakush
  • 3,334
  • 14
  • 47
  • 68
12
votes
2 answers

Are there facilities in std::chrono to assist with injecting system_clock for unit testing

I depend on hardware that may or may not respond. As a consequence I frequently end up writing functions with timeouts. System time is a known source for brittle unit tests so injecting a controlled and stable time seems like a good idea for…
Johannes
  • 6,490
  • 10
  • 59
  • 108
12
votes
4 answers

How to get system time in Haskell using Data.Time.Clock?

I'm needing some Ints to use as seed to random number generation and so I wanted to use the old trick of using the system time as seed. So I tried to use the Data.Time package and I managed to do the following: import Data.Time.Clock time =…
Rafael S. Calsaverini
  • 13,582
  • 19
  • 75
  • 132
10
votes
5 answers

Is there a Windows absolute time for timestamps? (.NET)

I'm working with a WPF/C# app where I need to lock out users from accessing a particular feature for some amount of time. Basically, from the time a certain event happens, I want to prevent certain access for the next 24 hours. The simple…
BabaBooey
  • 1,552
  • 3
  • 21
  • 38
9
votes
1 answer

Changing Android system clock stops timers. How can I restart them?

I need to run a periodic task in an Android application. I currently use a timer like this: final Handler guiHandler = new Handler(); // the task to run final Runnable myRunnable = new Runnable() { @Override public void run() { …
Alpha Hydrae
  • 2,891
  • 6
  • 26
  • 24
8
votes
1 answer

Modifying the date and time values using SYSTEMTIME, FILETIME, and ULARGE_INTEGER

I am making a program, in C++ using Visual Studio 2005, that needs to create a watermark with the time on a set of images. These images are taken from a video that were processed at certain time intervals. What I am trying to do is to modify the…
Seb
  • 3,414
  • 10
  • 73
  • 106
7
votes
3 answers

performing Arithmetic on SYSTEMTIME

I have a time value represented in SYSTEMTIME, i want to add/subtract 1 hour from it and get the newly obtained SYSTEMTIME. I want the conversion should take care of the date change on addition/subtraction or month change or e1 year change . Can…
Peter
  • 2,719
  • 4
  • 25
  • 55
7
votes
4 answers

Invalid max count in grep function

If I do a find . -mmin -1 I get 'myfile' which was modified in last one minute. But when I want to search a particular string in that file by doing grep 'myString' myfile -mmin -1 I get the error invalid max count I also tried find . -name…
Some Java Guy
  • 4,992
  • 19
  • 71
  • 108
7
votes
2 answers

How do I query InfluxDB to show me current time and date?

I couldn't find much documentation on this. How do I query InfluxDB to show me current database system time and date?
Tracy Ann Monteiro
  • 213
  • 3
  • 7
  • 14
1
2 3
11 12