clock

Android: How do I display an updating clock in a TextView

倾然丶 夕夏残阳落幕 提交于 2019-11-28 05:02:44
have a clock I want to display in a TextView. I would have thought there was a few nice functions to do this, but I couldn't find anything. I ended up implementing my own way that uses a Handler. What I'm asking though, is there a better (more efficient) way to display a real time updating clock? private Runnable mUpdateClockTask = new Runnable() { public void run() { setTime(); mClockHandler.postDelayed(this, 1000); } }; That's my handler, which runs every second, and then my set time and date function is below TextView mClockView; public void setTime() { Calendar cal = Calendar.getInstance()

Time in milliseconds in C

六月ゝ 毕业季﹏ 提交于 2019-11-28 03:55:28
Using the following code: #include<stdio.h> #include<time.h> int main() { clock_t start, stop; int i; start = clock(); for(i=0; i<2000;i++) { printf("%d", (i*1)+(1^4)); } printf("\n\n"); stop = clock(); //(double)(stop - start) / CLOCKS_PER_SEC printf("%6.3f", start); printf("\n\n%6.3f", stop); return 0; } I get the following output:

Detect with javascript if user's machine is using 12 hour clock (am/pm) or 24 clock (military time)

好久不见. 提交于 2019-11-28 02:58:17
问题 Is it possible to detect if user's machine is using 12 hour clock (am/pm) or 24 hour clock (military time)? One way would be to check users locales, but then it is just massive list of locale comparison and someone from U.S who wants 12 hour clock can send me just en locale, not US_en and I have no way of knowing her preferences. At the same time someone from U.S might be set her machine to use 12 hour time format and doesn't want 12 hour clock. EDIT: date.toLocaleTimeString(); Would work it

C: Different implementation of clock() in Windows and other OS?

天大地大妈咪最大 提交于 2019-11-28 01:19:25
I had to write a very simple console program for university that had to measure the time required to make an input. Therefor I used clock() in front and after an fgets() call. When running on my Windows computer it worked perfectly. However when running on my friends Mac-Book and Linux-PC it gave extremely small results (a few micro seconds of time only). I tried the following code on all 3 OS: #include <stdio.h> #include <time.h> #include <unistd.h> void main() { clock_t t; printf("Sleeping for a bit\n"); t = clock(); // Alternatively some fgets(...) usleep(999999); t = clock() - t; printf(

Linux Clock Architecture

感情迁移 提交于 2019-11-28 01:14:23
问题 In Linux how is the Clock Architecture implemented. There is a file include/linux/clkdev.h struct clk_lookup { struct list_head node; const char *dev_id; const char *con_id; struct clk *clk; }; What are the various fields and it is extensively used in Clock architecture in arch/arm/Board***/... ? 回答1: The generic Linux clock infra-structure is documented in clk.rst. For the ARM, Sasha Hauer created the common clock frame-work recently (last two years). The clocks are structured in a parent

Difference between clock() and MPI_Wtime()

强颜欢笑 提交于 2019-11-28 01:01:09
问题 Quick Question . for MPI implementation of my code ,i am getting a huge difference in both. I know MPI_Wtime is the real time elapsed by each processor and clock() gives a rough idea of the expected time . Do anyone wants to add some assertion ? 回答1: The clock function is utterly useless. It measures cpu time, not real time/wall time, and moreover it has the following serious issues: On most implementations, the resolution is extremely bad, for example, 1/100 of a second. CLOCKS_PER_SECOND is

Android: DigitalClock remove seconds

对着背影说爱祢 提交于 2019-11-28 00:11:08
I used this code for adding a clock to my app: <DigitalClock android:id="@+id/digitalclock" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:textSize = "30sp" /> The problem is that it shows also seconds..there is a simple and fast way for hide those? I need just hours and minutes in hh:mm format instead of hh:mm:ss! any suggestions? Thanks! IanTeda Found the answer here , for anyone else looking for a working answer, here it is: Clone/copy DigitalClock.java from android source Change format strings within new

How precise is the internal clock of a modern PC?

二次信任 提交于 2019-11-27 21:55:53
I know that 10 years ago, typical clock precision equaled a system-tick, which was in the range of 10-30ms. Over the past years, precision was increased in multiple steps. Nowadays, there are ways to measure time intervals in actual nanoseconds. However, usual frameworks still return time with a precision of only around 15ms. My question is, which steps did increase the precision, how is it possible to measure in nanoseconds, and why are we still often getting less-than-microsecond precision (for instance in .NET). (Disclaimer: It strikes me as odd that this was not asked before, so I guess I

How to get the precision of high_resolution_clock?

左心房为你撑大大i 提交于 2019-11-27 21:11:06
C++11 defines high_resolution_clock and it has the member types period and rep . But I can not figure out how I can get the precision of that clock. Or, if I may not get to the precision, can I somehow at least get a count in nanoseconds of the minimum representable time duration between ticks? probably using period ? #include <iostream> #include <chrono> void printPrec() { std::chrono::high_resolution_clock::rep x = 1; // this is not the correct way to initialize 'period': //high_resolution_clock::period y = 1; std::cout << "The smallest period is " << /* what to do with 'x' or 'y' here? */ <

Dynamic Clock in java

孤者浪人 提交于 2019-11-27 18:12:25
问题 I want to implement a clock within my program to diusplay the date and time while the program is running. I have looked into the getCurrentTime() method and Timer s but none of them seem to do what I would like. The problem is I can get the current time when the program loads but it never updates. Any suggestions on something to look into would be greatly appreciated! 回答1: What you need to do is use Swing's Timer class. Just have it run every second and update the clock with the current time.