C语言获取字符年月日时分秒毫秒
概述
- 本文演示环境: Windows10
- 使用C语言获取年月日时分秒毫秒,
代码
#include <iostream>
#include <string>
#include <time.h>
#include <sys/timeb.h>
using namespace std;
struct NowDate
{
char year_month_day_[16] = {0}; //年月日
char hour_minute_second_[16] = {0}; //时分秒
char mill_sec_[4] = {0}; //毫秒
};
/// 获取时间
NowDate getTime()
{
time_t timep;
time(&timep);
NowDate date;
strftime(date.year_month_day_, sizeof(date.year_month_day_), "%Y-%m-%d", localtime(&timep));
strftime(date.hour_minute_second_, sizeof(date.hour_minute_second_), "%H:%M:%S", localtime(&timep));
struct timeb tb;
ftime(&tb);
sprintf(date.mill_sec_, "%d", tb.millitm);
return date;
}
int main()
{
NowDate time = getTime();
cout << "year-month-day:" << time.year_month_day_ << endl;
cout << "hour-minute-second" << time.hour_minute_second_ << endl;
cout << "mill-seconds" << time.mill_sec_ << endl;
system("pause");
return 0;
}
输出

C语言获取字符年月日时分秒毫秒的更多相关文章
- 年月日时分秒毫秒+随机数getSerialNum
package com.creditharmony.apporveadapter.core.utils; import java.io.ByteArrayInputStream; import jav ...
- Asp.net(C#)年月日时分秒毫秒
年月日时分秒毫秒格式:yyyyMMddHHmmssfff
- Android Calendar获取年月日时分秒毫秒
开始使用new Date()测试,并用通过date.getMonth(),和date.getDay()获取,不过后来发现这两个访求是jdk1.1版本的,现在已经不用了,而且结果也不正确. ; int ...
- Java输出当前的日期(年月日时分秒毫秒)
package test.remote.tools.combine; import java.text.SimpleDateFormat; import java.util.Calendar; imp ...
- java日期格式(年月日时分秒毫秒)
package test.remote.tools.combine; import java.text.SimpleDateFormat; import java.util.Calendar; imp ...
- SqlSever基础 getdate函数 返回系统当前的年月日,时分秒 毫秒
镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...
- C# 版本的 计时器类:精确到微秒 秒后保留一位小数 支持年月日时分秒带单位的输出
class TimeCount { // 临时变量,存放当前类能表示的最大年份值 ; /// <summary> /// 获取毫秒能表示的最大年份数 /// </summary> ...
- JavaScript中的内置对象-8--4.date对象中-获取,设置日期时间的方法; 获取,设置年月日时分秒及星期的方法;
学习目标 1.掌握创建日期对象的方法 2.掌握date对象中获取日期时间的方法 3.掌握date对象中设置日期时间的方法 如何创建一个日期对象 语法:new Date(); 功能:创建一个日期时间对象 ...
- js获取当前时间的年月日时分秒以及时间的格式化
1.获取当前时间 var myDate = new Date(); 2.获取时间中的年月日时分秒 myDate.getYear(); // 获取当前年份(2位) myDate.getFullYear( ...
随机推荐
- 2基因组间鉴定SV
本文学习费章军老师文章Genome of Solanum pimpinellifolium provides insights into structural variants during toma ...
- GWAS在农业上应用
农业的组学技术应用虽然落后于人的研究,这是什么意义的问题,但有时农业基因组有自己无可比拟的优势,那就是材料.下面介绍GWAS应用. GWAS(Genome-wide association study ...
- MYSQL5.8----M4-5
mysql> CREATE TABLE joson( id INT AUTO_INCREMENT PRIMARY KEY, context JSON NOT NULL)// Query OK, ...
- shell 的 功能语句--1
[1]说明性语句 (1)shell 程序和语句 shell 程序由零或多条shell语句构成. shell语句包括三类:说明性语句.功能性语句和结构性语句. 说明性语句: 以#号开始到该行结束,不被解 ...
- 关于latex简历几个非常有用的命令
大家知道latex是最好的排版系统,用来写论文,排版非常漂亮,用来做简历可以提升逼格,下面介绍几个有用的命令 几个有用的命令 section.cventry.cvitem.cvlistit ...
- linux系统中安装MySQL
linux系统中安装MySQL 检查原来linux系统中安装的版本 rpm -qa | grep mysql 将其卸载掉 以 mysql-libs-5.1.71-1.el6.x86_64 版本为例 r ...
- LeetCode移除元素
LeetCode 移除元素 题目描述 给你一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,并返回移除后数组的新长度. 不需要使用额外的数组空间,你必须仅使用 O(1) ...
- A Child's History of England.19
The King was at first as blind and stubborn as kings usually have been whensoever [每当] they have bee ...
- day14函数递归调用
day14函数递归调用 1.装饰器叠加 def deco1(func1): def wrapper1(*args,**kwargs): print('=====>wrapper1 ') res1 ...
- Hadoop、Hive【LZO压缩配置和使用】
目录 一.编译 二.相关配置 三.为LZO文件创建索引 四.Hive为LZO文件建立索引 1.hive创建的lzo压缩的分区表 2.给.lzo压缩文件建立索引index 3.读取Lzo文件的注意事项( ...