Click here to Skip to main content
15,885,757 members
Everything / Time

Time

time

Great Reads

by Graham Wilson
An exercise to measure the drift in the time-of-day clock on a Windows PC using the periodic timer
by honey the codewitch
Create a simple synchronized analog clock using GFX, and a bit of code
by Keith Barrow
If you have a Winforms application that auto loads data, there is no doubt that you’ll have come across the problem of data loading at design time (i.e. when opening the code in the designer). At best, this slows the designer down, at worst it might crash VS and prevent the control from...
by honey the codewitch
std::chrono doesn't work on the Teensy? Oh no! Here's how to fix it.

Latest Articles

by honey the codewitch
Just a clock with snazzy digits that syncs using NTP and gets your timezone from your IP.
by honey the codewitch
std::chrono doesn't work on the Teensy? Oh no! Here's how to fix it.
by honey the codewitch
Create a clock that uses multiple Internet services to detect your weather, date and time
by honey the codewitch
Create a simple synchronized analog clock using GFX, and a bit of code

All Articles

Sort by Score

Time 

14 Jan 2017 by Graham Wilson
An exercise to measure the drift in the time-of-day clock on a Windows PC using the periodic timer
11 Jun 2022 by honey the codewitch
Create a simple synchronized analog clock using GFX, and a bit of code
28 Apr 2010 by Keith Barrow
If you have a Winforms application that auto loads data, there is no doubt that you’ll have come across the problem of data loading at design time (i.e. when opening the code in the designer). At best, this slows the designer down, at worst it might crash VS and prevent the control from...
17 Mar 2011 by JF2015
This code closes the form after 10s:System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();private void Form1_Load(object sender, EventArgs e){ timer.Interval = 10000; timer.Tick += new EventHandler(timer_Tick); timer.Start();}void timer_Tick(object sender,...
26 Mar 2013 by Volynsky Alex
For example you can try to settle it, by following way:#include #include int main(){ time_t your_time = .... struct tm your_time_tm = *localtime( &your_time); struct tm then_tm = your_time_tm; then_tm.tm_sec += 100; mktime(...
24 Aug 2022 by honey the codewitch
std::chrono doesn't work on the Teensy? Oh no! Here's how to fix it.
17 Mar 2011 by OriginalGriff
Yes.Timer formClose = new Timer();private void myForm_Load(object sender, EventArgs e) { formClose.Interval = 10000; formClose.Tick += new EventHandler(formClose_Tick); formClose.Start(); }void formClose_Tick(object sender, EventArgs e) { ...
19 Mar 2024 by honey the codewitch
Just a clock with snazzy digits that syncs using NTP and gets your timezone from your IP.
30 Dec 2011 by Manfred Rudolf Bihy
The problem is not in the code you posted, but where it is invoked. Somewhere either you directly or some part of the framework calls the function you mentioned with no parameters. The definition of said function takes two parameters none of which you nor the postulated framework...
20 Feb 2012 by ZC123456
As a developer who has spent a fair amount of time tweaking code for performance optimization, I'm having some issues with this article.First of all, who has generally accepted 10M iterations to test the performance? Unless your native code happens to be calling a function thousands or...
18 Jul 2013 by SoMad
You are fighting the classic Windows timer resolution issue. With a twist.By default, the timer resolution in Windows is 15.6ms, which means that when you start a periodic timer, specifying a 16.7ms interval, you might receive your next event exactly when you expect it or delayed by as much as...
12 Nov 2013 by SupperSlonic
control for edit a weekly schedule based on ASP.NET MVC
11 Sep 2014 by Matt T Heffron
The TimeSpan struct is your friend!Just create a new TimeSpan from the count in seconds, and use its .ToString(formatString) to format it:TimeSpan elapsed = TimeSpan.FromSeconds(elapsedTimeSecondsCounter);string elapsedFormatted = elapsed.ToString(@"m\:ss");
8 Mar 2021 by honey the codewitch
Traipsing through the ESP-IDF to add some sweet sweet real-time clock functionality
9 Jul 2011 by Sergey Alexandrovich Kryukov
You can time stamps several different events raised on different phases of recognition: SpeechDetected, SpeechHypothesized, SpeechRecognitionRejected and SpeechRecognized. Those are the events of the classes System.Speech.Recognition.SpeechRecognitionEngine or...
11 Apr 2012 by OriginalGriff
You can't do it that way. Sorry, but ASP doesn't work like that.When you read the DateTime.Now property, you get a single use, one shot, non-updating copy of the current date and time. Just like nearly all other objects in .NET, it will not change from this moment on, unless you specifically...
11 Oct 2013 by ASP.NET Community
CachingAuthor: Prakash Singh MehraIntroduction: It is a way to store the frequently used data into the server memory which can be retrieved very
17 Mar 2014 by Richard MacCutchan
You need to use the tzfile and tzset[^] functions to find the name.
3 May 2014 by OriginalGriff
You can use more than one timer in an app , but it's not a good idea, as timers are scarce resources and you shouldn't use more than you have to. I generally use just one (when I have to) and set it to 1/10th second or similar then use counters within the timer Tick event handler to process...
30 Dec 2022 by OriginalGriff
The last boot time is probably correct - it's just your idea of what you do with your computer that differs from Windows. With Win 10 / 11 (and maybe earlier, I'm not sure) "shutdown" and "restart" don't do what the name implies, not really -...
8 Jul 2011 by S Houghtelin
When the speech regonition identifies a word you can create a timestamp You can use the current time with DateTime:http://msdn.microsoft.com/en-us/library/efez4684.aspx[^]Or you can use a timer,http://msdn.microsoft.com/en-us/library/system.timers.timer(v=VS.100).aspx[^]Regards.
24 Dec 2011 by Monjurul Habib
while (true) { if (d.Key == ConsoleKey.UpArrow) { v--; } else if (d.Key == ConsoleKey.DownArrow) { v++; } else if (d.Key == ConsoleKey.RightArrow) { h++; } else if (d.Key == ConsoleKey.LeftArrow) { ...
11 Jan 2012 by Wendelius
What about these:- Personal Time Tracker[^]- N-Track : Work-Time tracking system[^]
19 Jan 2012 by Jochen Arndt
1. The utility uses the function ::GetSystemTimeAdjustment to get the intervals. And, as expected, ::SetSystemTimeAdjustment can change the interval.2. Using very high priorities is a very bad idea. You can lock your complete system. You may use ::QueryPerformanceCounter to measure time...
7 Feb 2012 by JackDingler
It looks like you write to the file with every iteration that (count%2) is true.Try adding a variable called lastcount and set it equal to -1.Then if count and lastcount are different, print to the file and make lastcount = count. if(lastcount != count) { ...
18 Jun 2012 by Alan N
From your comment on Mehdi's answer I see that the task duration can be much greater than the timer interval and your original solution is OK for that situation.The problem is how to repeat a task, not every 500ms, but 500ms after the task has completed.You have the timer based solution...
14 Feb 2013 by CS2011
If you mean adding two dates this will help System.DateTime today = System.DateTime.Now;System.TimeSpan duration = new System.TimeSpan(36, 0, 0, 0);System.DateTime answer = today.Add(duration);System.Console.WriteLine("{0:dddd}", answer);you can find more details about this in...
21 Mar 2013 by Stefan_Lang
1. Convert the string to hours, minutes and seconds2. combine these three numbers to calculate the total number of seconds3. Add 804. Split up the resulting value back to hours, minutes and seconds5. convert that back to string.There may be shortcuts or faster ways of doing this, but...
13 Apr 2013 by André Kraak
Use the DateTime.ToString[^] method.You can use the Standard Date and Time Format Strings[^] to get the time: DateTime.Now.ToString( "T" ) or the Custom Date and Time Format Strings[^]: DAteTime.Now.ToString( "HH:mm:ss" )
18 Jul 2013 by Alan N
Yes I can see this jittering effect on my computer too, or to be more accurate I could when a programme was being recorded from the USB digital TV tuner. Now that has stopped and the tuner has been unplugged the timer is quite regular. I was seeing SignalTime intervals of either 15.625ms or...
8 Sep 2013 by Joezer BH
Your line is just fine for converting your textbox's text to an int.//You could also use int.Parse(textBox1.Text);Using the counter variable in your code as seconds will be when you use it in the code's context.e.g. main(){ counter = Convert.Toint32(textBox1.Text.Trim()); ...
13 Oct 2013 by Ron Beyer
Unfortunately Windows is not a real-time operating system and its difficult to get the same (or close to the same) time on two different threads. Maybe your answer is doing post-processing instead of trying to get the values while also collecting data. For example, collect the data, save it to a...
7 Mar 2014 by leon de boer
What is there to be confused about think about it carefully.=> setTimeout() - executes a function, once, after waiting a specified number of millisecondsYou loop it thru the inside function twice ... How long do you think that will take?????The answer is very very very very fast like...
3 Aug 2014 by Andreas Gieriet
See DateTime[^] and TimeSpan[^].You basically do not deserve such an answer since you should have found it yourself: google: C# time difference... Or do you have a good reason to not look this up yourself?Andi
16 Jan 2015 by Richard Deeming
Custom Date and Time Format Strings[^]:string formattedDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");// Example output: 2015-01-16 16:26:32
16 Jan 2015 by Sergey Alexandrovich Kryukov
In addition to Solution 1:Please see all related methods:http://msdn.microsoft.com/en-us/library/system.datetime.tostring%28v=vs.110%29.aspx[^].What you need is formatting. is not "conversion". Note that parameters allows you to format depending on culture...
30 Jun 2016 by Philippe Mori
DirectoryInfo related stuff seems useless in your code.In your code, there is no code that send SMS so it is not possible to tell you where the problem is. However, it would be very easy for you to put a breakpoint on the code that does send the SMS and see why a message is sent.That...
20 Apr 2017 by OriginalGriff
First off, you dont; want to do that - there is no good reason for altering the time, since most Windows installations now use a NTP server by default to maintain the system time accurately - and the NTP server will override your app anyway. In addition, as Jochen said, you need admin...
29 Aug 2017 by OriginalGriff
You can't convert a Timespan to a DateTime: that doesn't work because it's not a logical action. Think about it: If I ask you to meet me at "plus 6 hours 30 minutes" what does that mean? Nothing - unless it's understood that there is a starting point for it to be relative to. In terms of normal...
29 Sep 2019 by Richard MacCutchan
See fibonacci sequence - Google Search[^]
2 May 2020 by Richard MacCutchan
Tank capacity 10,000 m3 Flowrate 1000 m3/hour At a guess that is 10 hours The actual calculation being capacity / flowrate.
16 Jun 2022 by honey the codewitch
Create a clock that uses multiple Internet services to detect your weather, date and time
18 Feb 2010 by Ron Beyer
If you are designing in a WinForms component, which is anything that derives from Control at some point (Forms, UserControls, panels, etc), then you can use the following code:if (this.Site.DesignMode) //Do stuff[edit]The above will throw an exception if Site is not set (in...
30 Aug 2010 by Sandeep Mewara
For showing server time, it would be good to use AJAX Timer control[^].
25 Jan 2011 by Kyudos
I built a query in MS Query / Excel, ending like this:... AND (TSDD.PeriodEndDatePosted>={ts '2010-01-01 00:00:00'} And TSDD.PeriodEndDatePosted= {ts...
25 Jan 2011 by Kyudos
Ignore me - I'm a dumbass!Once you've done the string replacement, it helps if you use the modified string for the query, not the original :doh:
2 Feb 2011 by soni uma
In Asp.net it is provide one simple feature is ..DateTime.DaysInMonth(2011, 02); Here you can get number of days in particular month. Now loop on days, bind your days dropdown.
26 May 2011 by Kim Togo
There is a SystemEvents.TimeChanged[^] event that is triggered when the user changes the time on the system clock.When the program is not running, you can store the value in DateTime.Now.IsDaylightSavingTime and use this to compare at next startup.
25 Jun 2011 by Kerem Guemruekcue
Hi,i do have C dll project based on VCP2008 and i would like to eliminate all link time dependencies of it to the VCRT 9.0 library. I already LoadLibrary/GetProcAddress/CallFunc all necessary msvcrt.dll functions i need from the standard system supplied msvcrt.dll and this works fine....
8 Jul 2011 by ebilpola23
Is there a way to get the time a spoken word was recognized in speech recognition? I am using C#, and the SAPI5.1So far, I found this decimal position = (decimal)sfs.Seek(0, SpeechStreamSeekPositionType.SSSPTRelativeToCurrentPosition)from hereI haven't tried it yetbut I want...
15 Sep 2011 by Uday P.Singh
check these out:Creating Serverside Clock Control Using ASP.NET Ajax and C#[^]http://basgun.wordpress.com/2008/02/27/realtime-dynamic-clock-using-aspnet-ajax-updatepanel/[^]hope it helps :)
15 Sep 2011 by Reiss
Depending on what you are actually going to use it for, wouldn't a simple javascript timer work - see this[^] for example
17 Sep 2011 by Tejas Vaishnav
function TimeToShow() { var dt = new Date(); var la = document.getElementById(""); ...
24 Dec 2011 by #realJSOP
Create a thread that checks for keyboard activity every X seconds. If the thread doesn't detect activity, do something. When the user kits a key, set a value indicating the datetime of the activity. This is the variable that the thread would check to see how long it's been since the last...
7 Feb 2012 by Richard MacCutchan
Rangek.runge...
11 Mar 2012 by Sergey Alexandrovich Kryukov
There is no such thing as "Italian time". Time is always System.DateTime. If you need to present it in Italian, it's not time, this is string, which has nothing to do with time.However, if you mean Italian time zone, you need to use the time zone class System.TimeZoneInfo, please...
11 Apr 2012 by Sergey Alexandrovich Kryukov
Now, I hope you got the explanation by OriginalGriff.Here comes my answer:You don't have to do it in JavaScript. Just add to your header: ... Can you...
31 Jul 2012 by OriginalGriff
Depends: if you are talking about adding an event to your class that users of your class can handle, then it's pretty easy - just add the code: /// /// Event to indicate [Description] /// public event EventHandler Name; /// /// Called to...
20 Jan 2013 by milenalukic
Hi,For consistency I would assume you require the server time and not the client pc time.All you need to do is set the Time on your table with a default of Getdate().
12 Apr 2013 by CPallini
Roughly speaking, I would first normalize the amplitude of the two graphs and then time-translate one of them until best superposition is reached.
30 Apr 2013 by TorstenH.
your are initalizing the Timer object again and again!Take it completly into the loop. I would also extend it with a custom object adding a name/identifier attribute to the Timer:public class MyTimer extends Timer{ private final strID; // final -> has to be set by...
1 Jun 2013 by Christian Graus
I would use a repeater, just because it will give you more control over how your time line is rendered. Then, just look at your data. Your data is all you can hope to show. You can show it any way you like, in a repeater.
20 Aug 2013 by Mike Meinz
I found this via Google:Automatic Timezone Detection Using JavaScript[^]jsTimezoneDetect[^]get client time zone from browser[^]Auto detect a time zone with JavaScript[^]
19 Aug 2013 by Joezer BH
Note that this is not a C# question since you need to detect the timezone on the client side. This means that you probably need to use Javascript to do the job.See: Auto detect a time zone with JavaScript[^]Or have a look at this W3Schools' tutorial[^] You can add values to the...
31 Aug 2013 by Mike Meinz
This works for me. The timer fires the Elapsed event every twenty seconds.Dim mytimer As New System.Timers.TimerSub MyRefresh() write2Size() mytimer = New System.Timers.Timer(20000) 'Starting Timer AddHandler mytimer.Elapsed, AddressOf OnTimedEvent mytimer.Enabled =...
1 Oct 2013 by phil.o
Check for TimeSpan structure.
11 Nov 2013 by Morgan Estes
You're not doing anything wrong in your code; it's complaining about the timezone settings in php.ini.In a standard PHP installation, the timezone is set around line 923 of php.ini. In a *nix install, you can find out where your file is located by passing a flag to the command line like...
19 Mar 2014 by Vaibhav_J_Jaiswal
Hi Friends,I have stuck at one point. I get milliseconds by using GetTickCount() function. Now I want to convert it in date-time format like HH:MM:SS format. Is MFC provide api to convert this directly, or I will use any other way? Please suggest me the solution.DWORD dwTickCount =...
14 Apr 2014 by Manas Bhardwaj
You can do something like this, but I would rather suggest you to look at you database design and store the value as proper types instead of string values.CREATE TABLE #Timings (START NVARCHAR(100), ENDS NVARCHAR(100), Timing NVARCHAR(100))INSERT #TimingsSELECT SUBSTRING(Timings, 1,...
15 May 2014 by Mehdi Gholam
127.0.0.1 is a loopback address for the local machine, you should be using the server machines lan ip address instead on your android device.run cmd.exe on your server and type ipconfig to see what your server's ip address is.
23 May 2014 by Regaloq
Hi i solved the problem.Click here for source
13 Jul 2014 by Dave Kreskowiak
Well, the function you found, SetCalendarInfo[^], says this in the documentation:Quote:This function only affects the user override portion of the calendar settings. It does not set the system defaults.The real question is WHY are you trying to modify the system calendar type? This is...
7 Aug 2014 by sumwale
I don't think there is a way in the linux system libraries to get that since the underlying libraries use the abbreviated forms only and the long forms are likely not available anywhere.However, the ICU library does have the requisite methods and many more. It is installed by default on most...
4 Sep 2014 by Duncan Edwards Jones
The addition is one machine instruction, and copying into a buffer is another so 2 clock cycles is the absolute minimum. So - .00000005 seconds (+/- 100%)
4 Sep 2014 by kavitha3
Hi ,I am not understanding what is your need and why ...But i can redirect u to Mr.Robert's Article.Its about ::How To: Measure execution time in C#[^]::
4 Sep 2014 by Rob Philpott
You can't. Depends on what speed the CPU is clocked at, what instruction set its running, what the JIT does, whether it gets 'inlined' or branched etc.
18 Dec 2014 by KarstenK
it is so easy if your google some minutes:int hour, min, sec;fscanf( input, "%ld:%ld:%ld", &hour, &min, &sec);
23 Feb 2016 by Kornfeld Eliyahu Peter
If you are using default settings, your application will be destroyed after 1740 minutes (29 hours), when the pool hosting it will recycle...From you code/explanation it seems that you do not understand the goal and purpose of a web application and try to use it a service instead...That will...
16 Jun 2017 by OriginalGriff
Stop converting to strings, and convert to DateTime instead: If your value in the DatagridView is a DateTime, then use it directly: DateTime i = (DateTime) datagridview.currentrow.cell[4].value; If it's a string, then Parse it: DateTime i; if...
2 Jul 2017 by Bryian Tan
You have 2 comma issues, one mentioned by @KornfeldEliyahuPeter Sum(MediumVal) As [Dine In], From Here is the other. As [MediumVal], FROM
15 Aug 2017 by Jochen Arndt
As far as I understand you are using an online compiler that times out. While I don't know for sure while that happens it might be that the compiler is initialising stack variables with default values (as other compilers do too at least with debug builds) which took some time. You have a very...
15 Aug 2017 by Patrice T
Those sites are giving you challenges. Quote: is it not optimized. Optimizing is exactly the object of the challenge. Most strait forward solution is never the right solution. Your program is optimum if requested 1 sum, but not if you are requested many partial sums. Said otherwise, the...
16 Jan 2018 by Pete O'Hanlon
It's possible but of very little value. As .NET is interpreted, it's not too hard to read the IL (yes, there are some hacks that prevent apps like Reflector from doing this but they can be worked around). Once you have the IL, you have the source. There's very little you can do to prevent a...
21 Jun 2018 by Jochen Arndt
To simplify calculations I would use a structure that does not contain the individual fields but a single or two values. If you only want to support Windows you can use the FILETIME structure (Windows)[^]. Alternatively and for general OS support use the timeval structure (Windows)[^]. Here...
7 Jul 2019 by OriginalGriff
Just ask Google: public static DateTime GetInternetTime() { HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.Google.com"); WebResponse response = myHttpWebRequest.GetResponse(); string todaysDates =...
7 Aug 2019 by MadMyche
Actually you cannot; as Date and Time types in most RDBMS systems are actually numbers. It is up to whatever program you are using to view the information to actually format it into a human-recognizable format at the presentation level. The way to do this is to present this is to use the...
29 Sep 2019 by Greg Utas
Hint: use a template whose template parameter is an int. Stronger hint: search online for the same solution for a factorial and adapt it.
3 May 2020 by Richard MacCutchan
Use the DateTime Struct (System) | Microsoft Docs[^]. It is a good idea to study the documentation so you learn some of the more common and useful classes.
3 May 2020 by phil.o
When you subtract two DateTime values, you get a TimeSpan value representing the duration between them: DateTime startDate = datetimepicker1.Value; Datetime now = DateTime.Now; // The datetime at the tick of the timer TimeSpan duration = now -...
13 Aug 2020 by Sandeep Mewara
I believe the clue is with it being always 9 hours difference. Couldn't it be because of the timezone setup on your system? I checked and PHP time() Function[^] provides the current time as a Unix timestamp in GMT. (timezone independent) I...
21 Nov 2020 by Dave Kreskowiak
That's not going to happen on Windows. You cannot get that kind of precision on a shared system that is not a real-time O/S. Events like that are guaranteed to happen NO SOONER THAN SCHEDULED. That does not mean exactly as scheduled.
25 Apr 2021 by Patrice T
I suspect an error in 𝑝𝑟𝑜𝑐𝑒𝑑𝑢𝑟𝑒 𝑀𝑎𝑡𝐸𝑙𝑒𝑚𝑒𝑛𝑡𝑠𝑆𝑢𝑚(𝐴[0 … 𝑛 − 1,0, … . 𝑚 − 1]) 𝑠𝑢𝑚 = 0; 𝑓𝑜𝑟 𝑖 = 0 𝑡𝑜 𝑛 − 1 𝑑𝑜 𝑓𝑜𝑟 𝑗 = 0 𝑡𝑜 𝑚 − 1 𝑑𝑜 𝑠𝑢𝑚 = 𝑠𝑢𝑚 + 𝐴[𝑖] // I would have expected A[i,j] 𝑒𝑛𝑑...
12 May 2021 by OriginalGriff
The solution is simpler: don't use Random like that. Declare a single Random instance at class level (static is fine) and use that for both values: private static Random rand = new Random(); ... int maxprvni = 10; int...
17 May 2021 by OriginalGriff
Quote: so again StreamReader reads a text file and then edits it like like MessageBox? No ... a StreamReader does what it says: reads a file from the beginning to the end. And the problem you have is that text files have no organization: you...
9 Apr 2022 by Patrice T
Quote: As far as I know, the compile-time will take longer the larger the input (larger in this situation means more input). Compile time is no linked with larger input, but runtime is linked to size of input. Quote: But I wonder, is the input...
21 May 2022 by OriginalGriff
The simple solution is: set your system clock to the current time and let the OS keep it accurate via an internet time server. The only common reason for changing the date and / or time is to fool software licences into thinking they are still...
17 Feb 2010 by Alaric Dailey
One thing that annoys me is huge companies that ignore time issues. Several of my clients have had huge networks across multiple timezones, and they wondered why logging times in the database were always off, everyone was logging in their local time, making it impossible to correlate logs. ...
22 Mar 2010 by superkuton
We have a biometric time recorder with a bundled software/application.Now we want to create a customized application. The first requirement would be how to get the time logs from the biometric time recorder.The recorder/equipment connects to its bundled application using an IP address...
22 Mar 2010 by Christian Graus
I guess you need to read the database that it logs to. Given that you used 'time' instead of the name of a language as your tag, I don't see how you can hope for more specific help, but either way, the best help you're likely to get is to be advised to read the manual that came with your...
18 Apr 2010 by Not Active
Why does the client need to know the time on the server? Where is this message being sent to on the server? I would just send the message and let the process on the server tell the time.