milliseconds

Get DateTime.Now with milliseconds precision

你。 提交于 2019-11-27 06:06:56
How can I exactly construct a time stamp of actual time with milliseconds precision? I need something like 16.4.2013 9:48:00:123. Is this possible? I have an application, where I sample values 10 times per second, and I need to show them in a graph. Jon Skeet How can I exactly construct a time stamp of actual time with milliseconds precision? I suspect you mean millisecond accuracy . DateTime has a lot of precision, but is fairly coarse in terms of accuracy. Generally speaking, you can't. Usually the system clock (which is where DateTime.Now gets its data from) has a resolution of around 10-15

Java - alternative to thread.sleep

强颜欢笑 提交于 2019-11-27 04:48:25
I have a requirement to pause a while loop for a specific number of milliseconds. I have tried using Thread.sleep(duration) but it is not accurate, especially in a looping scenario. Millisecond accuracy is important in my program. Here is the algorithm where I don't want to go back to check for condition until expectedElapsedTime has passed by. while (condition) { time = System.currentTimeMillis(); //do something if (elapsedTime(time) < expectedElapsedTime) ) { pause the loop // NEED SUBSTITUTE FOR Thread.sleep() } // Alternative that I have tried but not giving good results is while (

get execution time in milliseconds in R

落花浮王杯 提交于 2019-11-27 04:25:45
问题 I have read a solution to this using tic(), toc() functions tic <- function(gcFirst = TRUE, type=c("elapsed", "user.self", "sys.self")) { type <- match.arg(type) assign(".type", type, envir=baseenv()) if(gcFirst) gc(FALSE) tic <- proc.time()[type] assign(".tic", tic, envir=baseenv()) invisible(tic) } toc <- function() { type <- get(".type", envir=baseenv()) toc <- proc.time()[type] tic <- get(".tic", envir=baseenv()) print(toc - tic) invisible(toc) } tic(); -----code---- toc(); elapsed 0.15

Handling an update loop using C++ Chrono?

不羁的心 提交于 2019-11-27 02:56:55
问题 I'm definitely a bit lost with the new C++ chrono library. Here I have an update loop. It runs two operations: engine.Update() engine.Render() These are long operations, and it's hard to tell how long they are. Thus, we measure how long they took, then do some calculations and figure the best way to gradually call update before we call render. To do this, i'm using C++11's Chrono functionality. I chose it because it sounded like a good deal: More accurate, More platform dependent. I'm finding

Do something every x (milli)seconds in pygame

你离开我真会死。 提交于 2019-11-27 02:13:05
I'm learing Python and Pygame, and my first thing I'm making is a simple Snake game. I'm trying to make it so that the snake moves once every 0.25 seconds. Here is the part of my code that loops: while True: check_for_quit() clear_screen() draw_snake() draw_food() check_for_direction_change() move_snake() #How do I make it so that this loop runs at normal speed, but move_snake() only executes once every 0.25 seconds? pygame.display.update() I want all of the other function to run normally, but move_snake() to only occur once every 0.25 seconds. I've looked it up and found a few answers but

How to convert a string Date to long millseconds

假如想象 提交于 2019-11-27 01:54:53
I have a date inside a string, something like "12-December-2012". How can I convert this into milliseconds (long)? Jon Lin Using SimpleDateFormat String string_date = "12-December-2012"; SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yyyy"); try { Date d = f.parse(string_date); long milliseconds = d.getTime(); } catch (ParseException e) { e.printStackTrace(); } SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy"); Date date = (Date)formatter.parse("12-December-2012"); long mills = date.getTime(); Take a look to SimpleDateFormat class that can parse a String and return a Date and

Get milliseconds until midnight

痞子三分冷 提交于 2019-11-26 23:12:08
问题 I'm creating an Android widget that I want to update every night at midnight. I am using an AlarmManager and I need to find out how many milliseconds are left from the current time until midnight. Here's my code: AlarmManager mAlarmManager = (AlarmManager)context.getSystemService(android.content.Context.ALARM_SERVICE); mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, millisecondsUntilMidnight, mSrvcPendingingIntent); How can I calculate how many milliseconds are left until midnight? Thank you

How to convert time milliseconds to hours, min, sec format in JavaScript?

余生长醉 提交于 2019-11-26 22:47:08
问题 I have the time as milliseconds, but I want the time after conversion like 00:00:00 . Ex: In milliseconds=86400000. I want how many hours in that milliseconds like, 00:00:00 How to get it in JavaScript? 回答1: How about doing this by creating a function in javascript as shown below: function msToTime(duration) { var milliseconds = parseInt((duration % 1000) / 100), seconds = Math.floor((duration / 1000) % 60), minutes = Math.floor((duration / (1000 * 60)) % 60), hours = Math.floor((duration /

How to measure the a time-span in seconds using System.currentTimeMillis()?

送分小仙女□ 提交于 2019-11-26 22:35:41
问题 How to convert System.currentTimeMillis(); to seconds? long start6=System.currentTimeMillis(); System.out.println(counter.countPrimes(100000000)+" for "+start6); The console shows me 5761455 for 1307816001290 . I can't read how many seconds that is. Any help? 回答1: long start = System.currentTimeMillis(); counter.countPrimes(1000000); long end = System.currentTimeMillis(); System.out.println("Took : " + ((end - start) / 1000)); UPDATE An even more accurate solution would be: final long start =

JFreeChart DynamicTimeSeriesCollection with a period of n milliseconds

随声附和 提交于 2019-11-26 21:58:33
问题 I'm trying to define an applet with a chart that have to be updated every n milliseconds. For example every 500 milliseconds. This is a part of the code: dataSet = new DynamicTimeSeriesCollection(1, 200, new Millisecond()); dataSet.setTimeBase(new Millisecond()); When I launch the application it returns me a NullPointerException raised by the second line. If I replace Milliseconds with Seconds it works. The question is: how can I set a period of n milliseconds without having exceptions?