time

rand() seeding with time() problem

人走茶凉 提交于 2020-01-04 04:06:05
问题 I'm having difficulty figuring out how to use rand() and seeding it with time() using Xcode. I want to generate random decimal numbers between 0 and 1. The code gives me seemingly random numbers for elements 1 and 2, but element 0 is always somewhere around 0.077. Any ideas why this would be? My code is: #include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { double array[3]; double rand_max = RAND_MAX; srand((int)time(NULL)); for (int iii = 0; iii < 3; iii++) array[iii] =

Am I using tm/mktime wrong, and if not is there a workaround?

落花浮王杯 提交于 2020-01-04 03:54:25
问题 I think the following program should output the seconds to 1970 for the first day of every year from 1AD to 1970, preceded by the size of time_t on the system it's compiled on ( CHAR_BIT is a macro so I think you can't just copy the compiled executable around and assume it's correct though in practice everything uses 8 bit char s these days). #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> void do_time(int year) { time_t utc; struct tm tp;

Does UNIX time record Timezone?

狂风中的少年 提交于 2020-01-04 03:18:11
问题 I want to ask about UNIX time, Does UNIX time record Timezone? I moved my hosting from Chicago/America to JST. The problem is that my whole MySQL database has records of UNIX time (Chicago/America timezone) I have a PHP code to show the time ago (ex 3days ago, yesterday, etc) When I move to the new server it says tomorrow To avoid this tomorrow, is it ok to make the server down for one day in order to synchronize with the current server's timezone? I worry that the UNIX time doesn't only

Is Sleep() inaccurate?

ぃ、小莉子 提交于 2020-01-04 02:33:07
问题 I'm working on a timing system and I'll implement a timer class. #include <windows.h> #include <stdio.h> #include <time.h> int main() { clock_t t1, t2; t1 = clock(); Sleep(10); t2 = clock(); printf("%i\n", (int)(t2 - t1)); return 0; } This program should print "10" but it prints "15" or "16". I need more accurate which is less than 1 ms! Suggestions? (maybe with select()'s timeout?) NOTE: I've run this program on Windows 7 Ultimate x86. Program compiled with MinGW (C/C++) x86. NOW I THINK >>

Find time average of hh:mm:ss

孤街醉人 提交于 2020-01-04 01:37:07
问题 I have this fiddle that calculates average time with miliseconds. However, my DB stores data in format of hh:mm:ss. fiddle var times= [ '00:00:03.00', '00:00:05.00', '00:00:02.00', '00:00:06.00'], date = 0, result = ''; function offsetify(t){ return t < 10 ? '0' + t : t; } for(var x = 0; x < times.length; x++ ) { var tarr = times[x].split(':'); date += new Date(0, 0, 0, tarr[0], tarr[1], tarr[2].split('.')[0], tarr[2].split('.')[1]).getTime(); } var avg = new Date(date/times.length); result =

Delete all times less than a specified value

妖精的绣舞 提交于 2020-01-04 00:41:08
问题 This is probably a simple question however I am new to R and couldn't find an answer (or was googling the wrong thing). I am currently working on a project which involves deleting all Time values that are less than 5 minutes. An example of the data is as follows with the times created using the "lubridate" package. Time 19S 1M 24S 7M 53S 11M 6S . . . Now I wish to delete all values which are less than 5 minutes. Therefore the final dataset I wish to get is: Time 7M 53S 11M 6S . . . Any help

How to convert milliseconds to a date string?

扶醉桌前 提交于 2020-01-03 20:05:47
问题 I get a miliseconds string from the server like this: 1345623261. How can i convert this into a normal date format, e.g. 30.08.2012? I attempted using setMilliseconds , like so: new Date().setMilliseconds(time_posted).toLocaleString(); But this doesn't work. How to do that? 回答1: Assuming time_posted is a number representing timestamp, which is expressed in seconds (judging by the number of digits) - multiply it by 1000 to get a representation in milliseconds, and pass the result to the Date

How to convert milliseconds to a date string?

社会主义新天地 提交于 2020-01-03 20:05:01
问题 I get a miliseconds string from the server like this: 1345623261. How can i convert this into a normal date format, e.g. 30.08.2012? I attempted using setMilliseconds , like so: new Date().setMilliseconds(time_posted).toLocaleString(); But this doesn't work. How to do that? 回答1: Assuming time_posted is a number representing timestamp, which is expressed in seconds (judging by the number of digits) - multiply it by 1000 to get a representation in milliseconds, and pass the result to the Date

How to convert string to date without time in Swift 3?

孤者浪人 提交于 2020-01-03 18:58:10
问题 I have try to convert the date like 2017-02-11 string to date but the result give me back something like this 2017-02-10 16:00:00 +0000 . I am using the following code below. let localDate = dateFormatter.string(from: date) //2017-02-11 let dateFormatter2 = DateFormatter() dateFormatter2.dateFormat = "yyyy-MM-dd" let selectedDate = dateFormatter2.date(from: localDate) print("Did Select \(selectedDate)") // 2017-02-10 16:00:00 +0000 回答1: let dateWithTime = Date() let dateFormatter =

Converting seconds to human readable format MM:SS Java [duplicate]

跟風遠走 提交于 2020-01-03 18:37:31
问题 This question already has answers here : Formatting seconds and minutes (4 answers) Closed 5 years ago . How can I convert a long int of seconds to the human readable format MM:SS Only SS should be 0 padded so long = 67 -> 1:07 回答1: String readable = String.format("%d:%02d", s/60, s%60); 回答2: Use integer division by 60 to turn seconds in to whole minutes. The Modulus(%) of seconds by 60 will give the "leftover" seconds. Then use a string conversion to check for the necessity of 0 padding. int