打印当前日期和时间,记录微秒级时间日志的C程序
来源:互联网 发布:linux php 写入权限 编辑:程序博客网 时间:2024/05/17 06:00
打印当前日期和时间
C程序:
#include <time.h> #include <stdio.h> int main(void) { time_t t; time(&t);printf("The Calendar Time now is %s\n",ctime(&t));return 0; }
编译后运行程序,输出结果:
The Calendar Time now is Fri Jun 28 10:06:18 2013Press any key to continue
附加对应的python程序:
import timeprint time.ctime()
执行,输出结果:
'Fri Jun 28 10:10:31 2013'
参考资料:
python time模块详解
http://blog.csdn.net/kiki113/article/details/4033017
记录微秒级时间日志
logtest.h
#ifndef LOGTEST_H#define LOGTEST_H#include <stdio.h>#include <time.h>#include <sys/time.h>extern int Debugmode;extern int Logmode;extern int Testmode;// log fileextern const char *Filepath;// time parametersextern time_t T;extern struct timeval Start, End;// write log with timestampint writelog(char* str);// performance testint tick();int tock();#endif
logtest.c
#include "logtest.h"int Debugmode=0;int Logmode=0;int Testmode=0;// log fileconst char *Filepath="logfile.txt";// time parameterstime_t T;struct timeval Start, End;// write log with timestampint writelog(char* str){ FILE* logfilep; if(Debugmode != 0){ fputs(str, stdout); fputs("\n", stdout); } if(Logmode != 0){ time(&T); if ((logfilep = fopen(Filepath,"a+"))==NULL) { return -1; } fprintf(logfilep, "The calendar time now is %s\n",ctime(&T)); fprintf(logfilep, "%s\n\n", str); fclose(logfilep); } return 0;}// performance testint tick(){ if(Testmode != 0){ gettimeofday(&Start, NULL); } return 0;}int tock(){ FILE* logfilep; if(Testmode != 0){ gettimeofday(&End, NULL); if ((logfilep = fopen(Filepath,"a+"))==NULL) { return -1; } int dt = 1000000 * (End.tv_sec - Start.tv_sec) + (End.tv_usec - Start.tv_usec); fprintf(logfilep, "The time difference is %d us\n\n", dt); fclose(logfilep); } return 0;}
makefile:
C_COMPILER := gccRM := rm -rf EXE := ./main.PHONY: all clean# All Targetall: $(EXE)# Add inputs and outputs from these tool invocations to the build variables LIB_DIR := LIBS := OBJS := ./main.oUSER_OBJS := ./logtest.o# Tool invocations$(EXE): $(OBJS) $(USER_OBJS)@echo 'Building target: $@'@echo 'Invoking: GCC C Linker'$(C_COMPILER) -ldl $(LIB_DIR) $(LIBS) -o $@ $^@echo 'Finished building target: $@'@echo ' '# All of the sources participating in the build are defined hereINCLUDE_DIR := -I/usr/local/openssl/include# Each subdirectory must supply rules for building sources it contributes./%.o: ./%.c@echo 'Building file: $<'@echo 'Invoking: GCC C Compiler'$(C_COMPILER) -O0 -g3 -Wall $(INCLUDE_DIR) -o $@ -c $<@echo 'Finished building: $<'@echo ' 'clean:-$(RM) $(OBJS) $(USER_OBJS) $(EXE)-@echo ' '.SECONDARY:
0 0
- 打印当前日期和时间,记录微秒级时间日志的C程序
- Window系统下C/C++程序毫秒和微秒级程序运行时间的获取方法
- C程序获取当前日期和时间(第六章)
- 获得微秒级的时间
- C#--记录用户程序退出时间日志
- C/C++获取精确到微秒级的系统时间
- 统计程序运行时间 微秒级计时器
- C++ 微秒级统计程序运行时间
- Linux 下c获取当前时间(精确到秒和毫秒或者微秒)
- Linux 下c获取当前时间(精确到秒和毫秒或者微秒)
- (笔记)linux c获取当前时间的函数gettimeofday(毫秒微秒)
- C语言打印当前时间
- C语言打印当前时间
- 微秒时间的获取
- PHP microtime 返回当前 Unix 时间戳和微秒数
- 返回当前 Unix 时间戳和微秒数
- microtime 获取当前 Unix 时间戳和微秒数
- JavaScript 获取当前的日期和时间
- hadoop中hive和hbase的整合应用
- vim使用Vundle一键配置完美php IDE开发环境
- Java 8 彻底改变数据库访问
- 南邮OJ 2027 操作序列
- Cocos2d-x 框架概要说明
- 打印当前日期和时间,记录微秒级时间日志的C程序
- Linux服务器网络开发模型
- C++ 析构函数 构造函数 虚析构函数
- 让你提前认识软件开发(7):变量及函数的命名
- 以后这里就是我大脑的小硬盘啦
- 控制台中输出宽字符
- 动态设置表结构方案(一)
- 第三章作业
- 算法竞赛入门经典训练指南-P4例题3 分金币问题总结