systemtime

Getting getrusage() to measure system time in C

眉间皱痕 提交于 2019-11-30 08:18:10
问题 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 <sys/time.h> #include <sys/resource.h> #include <unistd.h> #include <stdio.h> int main() { struct rusage usage; struct timeval start, end; int i, j, k = 0; getrusage(RUSAGE_SELF, &usage); start = usage.ru_stime; for (i = 0; i < 10000; i++) { /* Double loop for more interesting results. */ for (j = 0;

Get creation date and time of a folder in batch script

☆樱花仙子☆ 提交于 2019-11-29 16:56:57
I am trying to get the creation date and time of a specific folder in Windows. Based on this answer , I have tried the following: @echo off set path_of_folder="C:\folderA\folderB\" if exist %path_of_folder% ( echo Path exists. for /f "skip=5 tokens=1,2 delims= " %%a in ('dir /a-d /tc %path_of_folder%') do set "dt=%%a" echo Created on: %%a, %%b ) ) else ( echo Path does not exist. ) pause Where I get this output: Path exists. Created on: 05/07/2017, 17:42 Created on: 05/07/2017, 17:42 Created on: 05/07/2017, 17:42 Created on: 05/07/2017, 17:42 Created on: 4, File(s) Created on: 0, Dir(s) Which

Getting getrusage() to measure system time in C

我的未来我决定 提交于 2019-11-29 09:47:50
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 <sys/time.h> #include <sys/resource.h> #include <unistd.h> #include <stdio.h> int main() { struct rusage usage; struct timeval start, end; int i, j, k = 0; getrusage(RUSAGE_SELF, &usage); start = usage.ru_stime; for (i = 0; i < 10000; i++) { /* Double loop for more interesting results. */ for (j = 0; j < 10000; j++) { k += 20; } } getrusage(RUSAGE_SELF, &usage); end = usage.ru_stime; printf("Started

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

牧云@^-^@ 提交于 2019-11-28 19:32:47
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 can roll-back their system date and time in order to maintain the validity of license. Is there any way in Java to detect the system date and time is changed. I have already tried Network Time Protocol to get the current date and time from a time server. You likely are storing a license file on the system. a) include the time that the software was

Get creation date and time of a folder in batch script

帅比萌擦擦* 提交于 2019-11-28 11:51:52
问题 I am trying to get the creation date and time of a specific folder in Windows. Based on this answer, I have tried the following: @echo off set path_of_folder="C:\folderA\folderB\" if exist %path_of_folder% ( echo Path exists. for /f "skip=5 tokens=1,2 delims= " %%a in ('dir /a-d /tc %path_of_folder%') do set "dt=%%a" echo Created on: %%a, %%b ) ) else ( echo Path does not exist. ) pause Where I get this output: Path exists. Created on: 05/07/2017, 17:42 Created on: 05/07/2017, 17:42 Created

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

杀马特。学长 韩版系。学妹 提交于 2019-11-27 19:01:05
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 assylias In your code, replace LocalDate.now() with LocalDate.now(clock); . You can then pass Clock.systemDefaultZone() for production and a fixed clock for testing. This is an example : First, inject the Clock . If you are using spring boot just do a : @Bean public Clock clock() { return Clock.systemDefaultZone(); } Second, call LocalDate.now(clock) in your code : @Component public class SomeClass{ @Autowired private Clock

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

我是研究僧i 提交于 2019-11-27 12:21:08
问题 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 can roll-back their system date and time in order to maintain the validity of license. Is there any way in Java to detect the system date and time is changed. I have already tried Network Time Protocol to get the current date and time from a time

How can I set the System Time in Java?

岁酱吖の 提交于 2019-11-26 10:42:59
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 \""+datetime.format(ntp_obj.getDest_Time())+"\""; try { Runtime.getRuntime().exec(cmd); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println(cmd); The output of cmd is: date -s "06/01/2011 17:59:01" But the System time is the same as before. I will set the time because I am writing an NTP-Client and there I get the time from a NTP

How can I set the System Time in Java?

北慕城南 提交于 2019-11-26 03:28:39
问题 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 \\\"\"+datetime.format(ntp_obj.getDest_Time())+\"\\\"\"; try { Runtime.getRuntime().exec(cmd); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println(cmd); The output of cmd is: date -s \"06/01/2011 17:59:01\" But the System time is

Override Java System.currentTimeMillis for testing time sensitive code

纵饮孤独 提交于 2019-11-26 02:29:27
问题 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 number of accounting jobs that revolve much of their logic around the current date (ie 1st of the month, 1st of the year, etc) Unfortunately, a lot of the legacy code calls functions such as new Date() or Calendar.getInstance() , both of which