Linux c中使用系统时间

asctime(将时间和日期以字符串格式表示)  
相关函数

time,ctime,gmtime,localtime
 
表头文件

#include
 
定义函数 .h>

char * asctime(const struct tm * timeptr);
 
函数说明

asctime()将参数timeptr所指的tm结构中的信息转

换成真实世界所使用的时间日期表示方法,然后将结果以字

符串形态返回。此函数已经由时区转换成当地时间,字符串

格式为:

“Wed Jun 30 21:49:08 1993\n”
 
返回值

返回一字符串表示目前当地的时间日期。

附加说明

若再调用相关的时间日期函数,此字符串可能会被破坏。此函数与ctime不同处在于传入的参数是不同的结构。

范例

  1. #include <time.h>
    main()
    {
    time_t timep;
    time (&timep);
    printf(“%s”,asctime(gmtime(&timep)));
    }

执行  Sat Oct 28 02:10:06 2000

ctime(将时间和日期以字符串格式表示)  
相关函数

time,asctime,gmtime,localtime
 
表头文件

#include
 
定义函数 .h>

char *ctime(const time_t *timep);
 
函数说明

ctime()将参数timep所指的time_t结构中的信息转

换成真实世界所使用的时间日期表示方法,然后将结果以字

符串形态返回。此函数已经由时区转换成当地时间,字符串

格式为“Wed Jun 30 21 :49 :08 1993\n”。若再调用相关的

时间日期函数,此字符串可能会被破坏。
 
返回值

返回一字符串表示目前当地的时间日期。
 
范例

  1. #include<time.h>
    main()
    {
    time_t timep;
    time (&timep);
    printf(“%s”,ctime(&timep));
    }

执行  Sat Oct 28 10 : 12 : 05 2000

时间: 2024-05-20 14:43:33

Linux c中使用系统时间的相关文章

Linux驱动中获取系统时间

最近在做VoIP方面的驱动,总共有16个FXS口和FXO口依次初始化,耗用的时间较多.准备将其改为多线程,首先需要确定哪个环节消耗的时间多,这就需要获取系统时间. #include <linux/time.h> /*头文件*/ struct timeval time_now; unsigned long int time_num;//获取的时间 do_gettimeofday(&time_now); time_num = time_now.tv_sec*1000+time_now.tv

C语言中的系统时间结构体类型

在C语言涉及中经常需要定时触发事件,涉及到获取系统时间,其结构体类型有多种.Unix/Linux系统下有以下几种时间结构: 1.time_t 类型:长整型,一般用来表示从1970-01-01 00:00:00时以来的秒数,精确度:秒:由函数time()获取: 该类型定义在头文件 /usr/include/sys/time.h 中: #define _TIME_T       typedef   long   time_t;             #endif 函数定义:time_t   tim

JAVA中获取系统时间

一. 获取当前系统时间和日期并格式化输出: import java.util.Date;import java.text.SimpleDateFormat; public class NowString {public static void main(String[] args) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式System.out.println(df.forma

Linux Windows 定时修改系统时间

#/bin/bash # beforTime=02:00 afterTime=08:00 beforTime=$(echo $beforTime | awk -F : {'print $1'}) afterTime=$(echo $afterTime | awk -F : {'print $1'}) Flag=0 while true do     sleep 2s     echo "date: $(date +"%Y-%m-%d %H:%M:%S")"     

linux和windows双系统时间错误解决方法

转自http://www.2cto.com/os/201204/126212.html windows时间会慢8小时,原因: 两个概念: UTC即Universal Time Coordinated,协调世界时 GMT 即Greenwich Mean Time,格林尼治平时 Windows 与 Mac/linux 缺省看待系统硬件时间的方式是不一样的: Windows把系统硬件时间当作本地时间(local time),即操作系统中显示的时间跟BIOS中显示的时间是一样的. linux/Unix/

Linux C 语言 获取系统时间信息

比如获取当前年份:        /* 获取当前系统时间 暂时不使用        int iyear = 0;        int sysyear = 0;        time_t now;        struct tm *timenow;        time(&now);        timenow = localtime(&now);        sysyear = timenow->tm_year+1900;        */linux下获取系统时间的方法

linux下如何修改系统时间

我们一般使用"date -s"命令来修改系统时间.比如将系统时间设定成2018年2月23日的命令如下. #date -s 02/23/2018 将系统时间设定成下午11点12分0秒的命令如下. #date -s 11:12:00 注意,这里说的是系统时间,是linux由操作系统维护的. 在系统启动时,Linux操作系统将时间从CMOS中读到系统时间变量中,以后修改时间通过修改系统时间实现.为了保持系统时间与CMOS时间的一致性,Linux每隔一段时间会将系统时间写入CMOS.由于该同步

Talend 将Oracle中数据导入到hive中,根据系统时间设置hive分区字段

首先,概览下任务图: 流程是,先用tHDFSDelete将hdfs上的文件删除掉,然后将oracle中的机构表中的数据导入到HDFS中:建立hive连接->hive建表->tJava获取系统时间->tHiveLoad将hdfs上的文件导入到hive表中. 下面介绍每一个组件的设置: tHDFSDelete_1: 机构: tHDFSOutput_1: hive: tHiveCreateTable: tJava_1: tHiveLoad_1: 在Context下面建一个内容变量: 这个内容变

MFC在static text中动态显示系统时间

1.添加static text ,ID为IDC_ShowTime 2,在OnInitDialog()中 SetTimer(1,1000,NULL);         //启动定时器 3.添加WM_TIMER消息处理函数,ontimer中添加如下代码: CString strTime; CTime tm; tm=CTime::GetCurrentTime(); strTime=tm.Format("%Y-%m-%d %H:%M:%S"); SetDlgItemText(IDC_ShowT