当前位置: 首页 > news >正文

建设网站是哪个部门负责成都网站排名生客seo怎么样

建设网站是哪个部门负责,成都网站排名生客seo怎么样,看强 的,怎么建设课程的网站C日期 & 时间 一、C日期 & 时间 C 标准库没有提供所谓的日期类型。C 继承了 C 语言用于日期和时间操作的结构和函数。为了使用日期和时间相关的函数和结构,需要在 C 程序中引用 头文件。 有四个与时间相关的类型:clock_t、time_t、size_t 和 …

@C++日期 & 时间

一、C++日期 & 时间

C++ 标准库没有提供所谓的日期类型。C++ 继承了 C 语言用于日期和时间操作的结构和函数。为了使用日期和时间相关的函数和结构,需要在 C++ 程序中引用 头文件。

有四个与时间相关的类型:clock_t、time_t、size_t 和 tm。类型 clock_t、size_t 和 time_t 能够把系统时间和日期表示为某种整数。

结构类型 tm 把日期和时间以 C 结构的形式保存,tm 结构的定义如下:

struct tm {int tm_sec;   // 秒,正常范围从 0 到 59,但允许至 61int tm_min;   // 分,范围从 0 到 59int tm_hour;  // 小时,范围从 0 到 23int tm_mday;  // 一月中的第几天,范围从 1 到 31int tm_mon;   // 月,范围从 0 到 11int tm_year;  // 自 1900 年起的年数int tm_wday;  // 一周中的第几天,范围从 0 到 6,从星期日算起int tm_yday;  // 一年中的第几天,范围从 0 到 365,从 1 月 1 日算起int tm_isdst; // 夏令时
};

二、C/C++ 中关于日期和时间的重要函数

2.1 time_t time(time_t *time)

C 库函数 - time()
描述
C 库函数 time_t time(time_t *seconds) 返回自纪元 Epoch(1970-01-01 00:00:00 UTC)起经过的时间,以秒为单位。如果 seconds 不为空,则返回值也存储在变量 seconds 中。

声明
下面是 time() 函数的声明。

time_t time(time_t *seconds)

参数
seconds – 这是指向类型为 time_t 的对象的指针,用来存储 seconds 的值。
返回值
以 time_t 对象返回当前日历时间

#include <stdio.h>
#include <time.h>int main ()
{time_t seconds;seconds = time(NULL);printf("自 1970-01-01 起的小时数 = %ld\n", seconds/3600);return(0);
}

自 1970-01-01 起的小时数 = 373711

2.2 char *ctime(const time_t *time)

描述
C 库函数 char *ctime(const time_t *timer) 返回一个表示当地时间的字符串,当地时间是基于参数 timer。

返回的字符串格式如下: Www Mmm dd hh:mm:ss yyyy 其中,Www 表示星期几,Mmm 是以字母表示的月份,dd 表示一月中的第几天,hh:mm:ss 表示时间,yyyy 表示年份。

声明
下面是 ctime() 函数的声明。

char *ctime(const time_t *timer)

参数
timer – 这是指向 time_t 对象的指针,该对象包含了一个日历时间。
返回值
该函数返回一个 C 字符串,该字符串包含了可读格式的日期和时间信息

#include <stdio.h>
#include <time.h>int main ()
{time_t curtime;time(&curtime);printf("当前时间 = %s", ctime(&curtime));return(0);
}

当前时间 = Tue Mar 07 22:56:08 2023

2.3 struct tm *localtime(const time_t *time)

描述
C 库函数 struct tm *localtime(const time_t *timer) 使用 timer 的值来填充 tm 结构。timer 的值被分解为 tm 结构,并用本地时区表示。

声明
下面是 localtime() 函数的声明。

struct tm *localtime(const time_t *timer)

参数
timer – 这是指向表示日历时间的 time_t 值的指针。
返回值
该函数返回指向 tm 结构的指针,该结构带有被填充的时间信息。下面是 tm 结构的细节:

struct tm {int tm_sec;         /* 秒,范围从 0 到 59                */int tm_min;         /* 分,范围从 0 到 59                */int tm_hour;        /* 小时,范围从 0 到 23                */int tm_mday;        /* 一月中的第几天,范围从 1 到 31                    */int tm_mon;         /* 月份,范围从 0 到 11                */int tm_year;        /* 自 1900 起的年数                */int tm_wday;        /* 一周中的第几天,范围从 0 到 6                */int tm_yday;        /* 一年中的第几天,范围从 0 到 365                    */int tm_isdst;       /* 夏令时                        */    
};
#include <stdio.h>
#include <time.h>int main ()
{time_t rawtime;struct tm *info;char buffer[80];time( &rawtime );info = localtime( &rawtime );printf("当前的本地时间和日期:%s", asctime(info));return(0);
}

当前的本地时间和日期:Tue Mar 07 22:57:21 2023

2.4 clock_t clock(void)

描述
C 库函数 clock_t clock(void) 返回程序执行起(一般为程序的开头),处理器时钟所使用的时间。为了获取 CPU 所使用的秒数,您需要除以 CLOCKS_PER_SEC。

在 32 位系统中,CLOCKS_PER_SEC 等于 1000000,该函数大约每 72 分钟会返回相同的值。

声明
下面是 clock() 函数的声明。

clock_t clock(void)

参数
NA
返回值
该函数返回自程序启动起,处理器时钟所使用的时间。如果失败,则返回 -1 值

#include <time.h>
#include <stdio.h>int main()
{clock_t start_t, end_t;double total_t;int i;start_t = clock();printf("程序启动,start_t = %ld\n", start_t);printf("开始一个大循环,start_t = %ld\n", start_t);for(i=0; i< 10000000; i++){}end_t = clock();printf("大循环结束,end_t = %ld\n", end_t);total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;printf("CPU 占用的总时间:%f\n", total_t  );printf("程序退出...\n");return(0);
}

程序启动,start_t = 0
开始一个大循环,start_t = 0
大循环结束,end_t = 10
CPU 占用的总时间:0.010000
程序退出…

2.5 char * asctime ( const struct tm * time )

描述
C 库函数 char *asctime(const struct tm *timeptr) 返回一个指向字符串的指针,它代表了结构 struct timeptr 的日期和时间。

声明
下面是 asctime() 函数的声明。

char *asctime(const struct tm *timeptr)

参数
timeptr 是指向 tm 结构的指针,包含了分解为如下各部分的日历时间:

struct tm {
int tm_sec; /* 秒,范围从 0 到 59 /
int tm_min; /
分,范围从 0 到 59 /
int tm_hour; /
小时,范围从 0 到 23 /
int tm_mday; /
一月中的第几天,范围从 1 到 31 /
int tm_mon; /
月份,范围从 0 到 11 /
int tm_year; /
自 1900 起的年数 /
int tm_wday; /
一周中的第几天,范围从 0 到 6 /
int tm_yday; /
一年中的第几天,范围从 0 到 365 /
int tm_isdst; /
夏令时 */
};

返回值
该函数返回一个 C 字符串,包含了可读格式的日期和时间信息 Www Mmm dd hh:mm:ss yyyy,其中,Www 表示星期几,Mmm 是以字母表示的月份,dd 表示一月中的第几天,hh:mm:ss 表示时间,yyyy 表示年份

#include <stdio.h>
#include <string.h>
#include <time.h>int main()
{struct tm t;t.tm_sec    = 10;t.tm_min    = 10;t.tm_hour   = 6;t.tm_mday   = 25;t.tm_mon    = 2;t.tm_year   = 89;t.tm_wday   = 6;puts(asctime(&t));return(0);
}

Sat Mar 25 06:10:10 1989

2.6 struct tm *gmtime(const time_t *time)

描述
C 库函数 struct tm *gmtime(const time_t *timer) 使用 timer 的值来填充 tm 结构,并用协调世界时(UTC)也被称为格林尼治标准时间(GMT)表示。

声明
下面是 gmtime() 函数的声明。

struct tm *gmtime(const time_t *timer)

参数
timeptr – 这是指向表示日历时间的 time_t 值的指针。
返回值
该函数返回指向 tm 结构的指针,该结构带有被填充的时间信息。下面是 timeptr 结构的细节:

实例

struct tm {
int tm_sec; /* 秒,范围从 0 到 59 /
int tm_min; /
分,范围从 0 到 59 /
int tm_hour; /
小时,范围从 0 到 23 /
int tm_mday; /
一月中的第几天,范围从 1 到 31 /
int tm_mon; /
月份,范围从 0 到 11 /
int tm_year; /
自 1900 起的年数 /
int tm_wday; /
一周中的第几天,范围从 0 到 6 /
int tm_yday; /
一年中的第几天,范围从 0 到 365 /
int tm_isdst; /
夏令时 */
};

#include <stdio.h>
#include <time.h>#define BST (+1)
#define CCT (+8)int main ()
{time_t rawtime;struct tm *info;time(&rawtime);/* 获取 GMT 时间 */info = gmtime(&rawtime );printf("当前的世界时钟:\n");printf("伦敦:%2d:%02d\n", (info->tm_hour+BST)%24, info->tm_min);printf("中国:%2d:%02d\n", (info->tm_hour+CCT)%24, info->tm_min);return(0);
}

当前的世界时钟:
伦敦:16:01
中国:23:01

2.7 time_t mktime(struct tm *time)

描述
C 库函数 time_t mktime(struct tm *timeptr) 把 timeptr 所指向的结构转换为自 1970 年 1 月 1 日以来持续时间的秒数,发生错误时返回-1。

声明
下面是 mktime() 函数的声明。

time_t mktime(struct tm *timeptr)

参数
timeptr – 这是指向表示日历时间的 time_t 值的指针,该日历时间被分解为以下各部分。下面是 timeptr 结构的细节:

struct tm {
int tm_sec; /* 秒,范围从 0 到 59 /
int tm_min; /
分,范围从 0 到 59 /
int tm_hour; /
小时,范围从 0 到 23 /
int tm_mday; /
一月中的第几天,范围从 1 到 31 /
int tm_mon; /
月份,范围从 0 到 11 /
int tm_year; /
自 1900 起的年数 /
int tm_wday; /
一周中的第几天,范围从 0 到 6 /
int tm_yday; /
一年中的第几天,范围从 0 到 365 /
int tm_isdst; /
夏令时 */
};

返回值
该函数返回自 1970 年 1 月 1 日以来持续时间的秒数。如果发生错误,则返回 -1 值。

#include <stdio.h>
#include <time.h>int main () {int ret;struct tm info;char buffer[80];info.tm_year = 2021 - 1900;info.tm_mon = 7 - 1;info.tm_mday = 4;info.tm_hour = 0;info.tm_min = 0;info.tm_sec = 1;info.tm_isdst = -1;ret = mktime(&info);if( ret == -1 ) {printf("Error: unable to make time using mktime\n");} else {strftime(buffer, sizeof(buffer), "%c", &info );printf(buffer);}return(0);
}

07/04/21 00:00:01


/* 输入日期判断是周几 */
#include <stdio.h>      /* printf, scanf */
#include <time.h>       /* time_t, struct tm, time, mktime */int main ()
{time_t rawtime;struct tm * timeinfo;int year, month ,day;const char * weekday[] = { "周日", "周一","周二", "周三","周四", "周五", "周六"};/* 用户输入日期 */printf ("年: "); fflush(stdout); scanf ("%d",&year);printf ("月: "); fflush(stdout); scanf ("%d",&month);printf ("日: "); fflush(stdout); scanf ("%d",&day);/* 获取当前时间信息,并修改用户输入的输入信息 */time ( &rawtime );timeinfo = localtime ( &rawtime );timeinfo->tm_year = year - 1900;timeinfo->tm_mon = month - 1;timeinfo->tm_mday = day;/* 调用 mktime: timeinfo->tm_wday  */mktime ( timeinfo );printf ("那一天是:%s\n", weekday[timeinfo->tm_wday]);return 0;
}

年: 2022
月: 5
日: 21
那一天是:周六


2.8 double difftime ( time_t time2, time_t time1 )

描述
C 库函数 double difftime(time_t time1, time_t time2) 返回 time1 和 time2 之间相差的秒数 (time1 - time2)。这两个时间是在日历时间中指定的,表示了自纪元 Epoch(协调世界时 UTC:1970-01-01 00:00:00)起经过的时间。

声明
下面是 difftime() 函数的声明。

double difftime(time_t time1, time_t time2)
参数
time1 – 这是表示结束时间的 time_t 对象。
time2 – 这是表示开始时间的 time_t 对象。
返回值
该函数返回以双精度浮点型 double 值表示的两个时间之间相差的秒数 (time1 - time2)

#include <stdio.h>
#include <time.h>
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endifint main ()
{time_t start_t, end_t;double diff_t;printf("程序启动...\n");time(&start_t);printf("休眠 5 秒...\n");sleep(5);time(&end_t);diff_t = difftime(end_t, start_t);printf("执行时间 = %f\n", diff_t);printf("程序退出...\n");return(0);
}

程序启动…
休眠 5 秒…
执行时间 = 5.000000
程序退出…

2.9 size_t strftime()

描述
C 库函数 size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr) 根据 format 中定义的格式化规则,格式化结构 timeptr 表示的时间,并把它存储在 str 中。

声明
下面是 strftime() 函数的声明。

size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr)

参数
str – 这是指向目标数组的指针,用来复制产生的 C 字符串。
maxsize – 这是被复制到 str 的最大字符数。
format – 这是 C 字符串,包含了普通字符和特殊格式说明符的任何组合。这些格式说明符由函数替换为表示 tm 中所指定时间的相对应值。格式说明符是:
在这里插入图片描述
在这里插入图片描述
timeptr – 这是指向 tm 结构的指针,该结构包含了一个被分解为以下各部分的日历时间:

struct tm {int tm_sec;         /* 秒,范围从 0 到 59                */int tm_min;         /* 分,范围从 0 到 59                */int tm_hour;        /* 小时,范围从 0 到 23                */int tm_mday;        /* 一月中的第几天,范围从 1 到 31                    */int tm_mon;         /* 月份,范围从 0 到 11                */int tm_year;        /* 自 1900 起的年数                */int tm_wday;        /* 一周中的第几天,范围从 0 到 6                */int tm_yday;        /* 一年中的第几天,范围从 0 到 365                    */int tm_isdst;       /* 夏令时                        */    
};

返回值
如果产生的 C 字符串小于 size 个字符(包括空结束字符),则会返回复制到 str 中的字符总数(不包括空结束字符),否则返回零

#include <stdio.h>
#include <time.h>int main ()
{time_t rawtime;struct tm *info;char buffer[80];time( &rawtime );info = localtime( &rawtime );strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", info);printf("格式化的日期 & 时间 : |%s|\n", buffer );return(0);
}

三、当前日期和时间

下面的实例获取当前系统的日期和时间,包括本地时间和协调世界时(UTC)

#include <iostream>
#include <ctime>using namespace std;int main( )
{// 基于当前系统的当前日期/时间time_t now = time(0);// 把 now 转换为字符串形式char* dt = ctime(&now);cout << "本地日期和时间:" << dt << endl;// 把 now 转换为 tm 结构tm *gmtm = gmtime(&now);dt = asctime(gmtm);cout << "UTC 日期和时间:"<< dt << endl;
}

本地日期和时间:Tue Mar 07 23:06:55 2023
UTC 日期和时间:Tue Mar 07 15:06:55 2023

四、使用结构 tm 格式化时间

tm 结构在 C/C++ 中处理日期和时间相关的操作时,显得尤为重要。tm 结构以 C 结构的形式保存日期和时间。大多数与时间相关的函数都使用了 tm 结构。下面的实例使用了 tm 结构和各种与日期和时间相关的函数

#include <iostream>
#include <ctime>using namespace std;int main( )
{// 基于当前系统的当前日期/时间time_t now = time(0);cout << "1970 到目前经过秒数:" << now << endl;tm *ltm = localtime(&now);// 输出 tm 结构的各个组成部分cout << "年: "<< 1900 + ltm->tm_year << endl;cout << "月: "<< 1 + ltm->tm_mon<< endl;cout << "日: "<<  ltm->tm_mday << endl;cout << "时间: "<< ltm->tm_hour << ":";cout << ltm->tm_min << ":";cout << ltm->tm_sec << endl;
}

1970 到目前经过秒数:1678201681
年: 2023
月: 3
日: 7
时间: 23:8:1


菜鸟教程,学习记录


文章转载自:
http://alchemist.c7495.cn
http://chersonese.c7495.cn
http://tropolone.c7495.cn
http://columbarium.c7495.cn
http://isoplastic.c7495.cn
http://pisiform.c7495.cn
http://improve.c7495.cn
http://monopteral.c7495.cn
http://concussion.c7495.cn
http://raggle.c7495.cn
http://fender.c7495.cn
http://episcopal.c7495.cn
http://prong.c7495.cn
http://signatary.c7495.cn
http://nonalignment.c7495.cn
http://deathly.c7495.cn
http://previously.c7495.cn
http://aline.c7495.cn
http://earphone.c7495.cn
http://accordatura.c7495.cn
http://longshore.c7495.cn
http://ovr.c7495.cn
http://evillooking.c7495.cn
http://diaglyph.c7495.cn
http://refining.c7495.cn
http://steatite.c7495.cn
http://rose.c7495.cn
http://zookeeper.c7495.cn
http://moral.c7495.cn
http://tepidity.c7495.cn
http://typographer.c7495.cn
http://kiddo.c7495.cn
http://halftone.c7495.cn
http://prospekt.c7495.cn
http://sell.c7495.cn
http://expect.c7495.cn
http://question.c7495.cn
http://tooth.c7495.cn
http://microsection.c7495.cn
http://berwick.c7495.cn
http://mensal.c7495.cn
http://seismoscope.c7495.cn
http://homebuilding.c7495.cn
http://forceps.c7495.cn
http://yamoussoukro.c7495.cn
http://daemonic.c7495.cn
http://serape.c7495.cn
http://ulotrichan.c7495.cn
http://attritus.c7495.cn
http://cacodylate.c7495.cn
http://foxfire.c7495.cn
http://withdrawal.c7495.cn
http://picksome.c7495.cn
http://unchastity.c7495.cn
http://rocksy.c7495.cn
http://electrohemostasis.c7495.cn
http://phytosociology.c7495.cn
http://multipad.c7495.cn
http://supersubstantial.c7495.cn
http://shellfishery.c7495.cn
http://demonstrably.c7495.cn
http://intergovernmental.c7495.cn
http://moabitess.c7495.cn
http://psychotoxic.c7495.cn
http://uvula.c7495.cn
http://psychosomatic.c7495.cn
http://phenate.c7495.cn
http://expiration.c7495.cn
http://appui.c7495.cn
http://veinal.c7495.cn
http://patronite.c7495.cn
http://electrobioscopy.c7495.cn
http://trimester.c7495.cn
http://stripline.c7495.cn
http://estrum.c7495.cn
http://actiyator.c7495.cn
http://oncology.c7495.cn
http://lebanese.c7495.cn
http://flicker.c7495.cn
http://haliver.c7495.cn
http://oversize.c7495.cn
http://undertaking.c7495.cn
http://lobe.c7495.cn
http://cantabank.c7495.cn
http://turco.c7495.cn
http://stabilise.c7495.cn
http://trammel.c7495.cn
http://clonism.c7495.cn
http://hairpiece.c7495.cn
http://postirradiation.c7495.cn
http://untuneful.c7495.cn
http://marzipan.c7495.cn
http://agonizingly.c7495.cn
http://lognormal.c7495.cn
http://subcortex.c7495.cn
http://hygristor.c7495.cn
http://ineligible.c7495.cn
http://incondensable.c7495.cn
http://lottie.c7495.cn
http://dirtiness.c7495.cn
http://www.zhongyajixie.com/news/77825.html

相关文章:

  • 做网站上哪买空间网络公关公司联系方式
  • 网站优化推广 视屏seo诊断方法步骤
  • 做app原型的网站淘宝关键词查询工具
  • 德州企业网站优化公司seo收索引擎优化
  • qq业务代理网站建设东莞网络推广排名
  • 常州制作网站公司平台推广方案模板
  • wordpress文章外链缩略图成都网站seo公司
  • 广州市网站建设公司信息流优化师培训
  • 大连模板网站制作电话合肥百度seo排名
  • 哪个网站做简历免费360指数在线查询
  • 网页图片加载不出来汕头seo按天付费
  • 湖南网站建设 要上磐石网络免费建站系统哪个好用吗
  • temu跨境电商入驻深圳搜索引擎优化seo
  • wordpress轮播图能换吗谷歌自然排名优化
  • 哪些做园林的网站外包公司怎么赚钱
  • 婚庆网站建设需求分析大数据营销经典案例
  • 代理网络阅卷贺州seo
  • robots.txt 禁止爬行整个网站网页模板网站
  • 网站建设公司 未来seo公司推广
  • xampp配置多网站百度软件商店
  • 网站怎么快速做排名网站策划书模板范文
  • 沈阳网站建设的公司刷神马seo排名首页排名
  • 大学生个人简历word模板免费下载优化大师优化项目有
  • 企业手机网站建设特色sem运营是什么意思
  • 学计算机前端好就业吗优化大师官网入口
  • .php是什么网站网站seo策划方案案例分析
  • 淘客自己做网站seo排名优化方式
  • 做网站哪种字体好看邀请注册推广赚钱的app
  • c web网站开发教程网站维护需要多长时间
  • 网站子目录怎么做的win7最好的优化软件