#include <time.h> 
#include <stdio.h> 
int main( void ) 

    time_t t = time(0); 
    char tmp[64]; 
    strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A 本年第%j天 %z",localtime(&t) ); 
    puts( tmp ); 
    return 0; 
}
size_t strftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr);
根据格式字符串生成字符串。
struct tm *localtime(const time_t *timer);
取得当地时间,localtime获取的结果由结构tm返回
返回的字符串可以依下列的格式而定:
%a 星期几的缩写。Eg:Tue 
%A 星期几的全名。 Eg: Tuesday
%b 月份名称的缩写。 
%B 月份名称的全名。 
%c 本地端日期时间较佳表示字符串。 
%d 用数字表示本月的第几天 (范围为 00 至 31)。日期
%H 用 24 小时制数字表示小时数 (范围为 00 至 23)。 
%I 用 12 小时制数字表示小时数 (范围为 01 至 12)。 
%j 以数字表示当年度的第几天 (范围为 001 至 366)。 
%m 月份的数字 (范围由 1 至 12)。
%M 分钟。 
%p 以 ''AM'' 或 ''PM'' 表示本地端时间。 
%S 秒数。 
%U 数字表示为本年度的第几周,第一个星期由第一个周日开始。 
%W 数字表示为本年度的第几周,第一个星期由第一个周一开始。 
%w 用数字表示本周的第几天 ( 0 为周日)。 
%x 不含时间的日期表示法。 
%X 不含日期的时间表示法。 Eg: 15:26:30
%y 二位数字表示年份 (范围由 00 至 99)。 
%Y 完整的年份数字表示,即四位数。 Eg:2008
%Z(%z) 时区或名称缩写。Eg:中国标准时间 
%% % 字符。

//方案二 优点:能精确到毫秒级;缺点:使用了windows API 
#include <windows.h> 
#include <stdio.h> 
int main( void ) 

SYSTEMTIME sys; 
GetLocalTime( &sys ); 
printf( "%4d/%02d/%02d %02d:%02d:%02d.%03d 星期%1d\n",sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute, sys.wSecond,sys.wMilliseconds,sys.wDayOfWeek); 
return 0;
}
//方案三,优点:利用系统函数,还能修改系统时间
//此文件必须是c++文件
#include<stdlib.h>
#include<iostream>
using namespace std;
void main()
{
    system("time");
}
//方案四,将当前时间折算为秒级,再通过相应的时间换算即可
//此文件必须是c++文件
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
time_t now_time;
now_time = time(NULL);
cout<<now_time;
return 0;
}

C++ 获取当前时间的更多相关文章

  1. iOS中获取当前时间,设定时间,并算出差值

    NSDate *date = [NSDate date];//获取当前时间 NSTimeZone *zone = [NSTimeZone systemTimeZone];//修改时区 NSIntege ...

  2. Js获取当前日期时间及其它操作

    Js获取当前日期时间及其它操作var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); //获取完整的年份 ...

  3. 【转】Js获取当前日期时间及格式化操作

    (转自:http://www.cnblogs.com/qinpengming/archive/2012/12/03/2800002.html) var myDate = new Date(); myD ...

  4. PHP 获取中国时间,即上海时区时间

    /** * 获取中国时间,即上海时区时间 * @param <type> $format * @return <type> */ function getChinaTime($ ...

  5. C#获取北京时间与设置系统时间

    获取北京时间 public static DateTime GetBeijingTime() { DateTime dt; // 返回国际标准时间 // 只使用 timeServers 的 IP 地址 ...

  6. jquery 获取日期时间

    获取JavaScript 的时间使用内置的Date函数完成 var mydate = new Date();mydate.getYear(); //获取当前年份(2位)mydate.getFullYe ...

  7. 使用 jquery 获取当前时间的方法

    我们在写一些效果时,经常要用到 jquery 获取当前时间,但是jquery 目前并没有提供直接获取当前时间的 api 或者函数,所以我们还是得用原生的 javascript 时间对象 Date 来获 ...

  8. java学习第13天( java获取当前时间,有关大数据的运算及精确数字运算,Date类)

    一 java获取当前时间 学习一个函数,得到当前时间的准确值 System.currectTimeMillis(). 可以得到以毫秒为单位的当前时间.它主要用于计算程序运行时间,long start= ...

  9. js获取当前时间显示在页面上

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  10. Android获取系统时间方法的总结

    Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...

随机推荐

  1. .NET执行SQL插入时间的问题

    错误描述: 一个项目,源码是BOSS给的,部署到网上了,运行没有问题,可是在本地运行,就会有问题,问题在于往一些表插入记录的时候,本地不管怎么样都插入不了,而网上就可以插入,都是相同的一份代码 解决: ...

  2. HTML5背景音乐的暂停与播放

    HTML代码:     <audio id="myaudio" loop="loop" preload="auto" autoplay ...

  3. Python 计算两个IP段之间的有效IP地址

    Can anyone think of an algorithm to put all of the addresses between two others and put them in a li ...

  4. TensorFlow运作方式入门

    TensorFlow运作方式入门 代码:tensorflow/g3doc/tutorials/mnist/ 本篇教程的目的,是向大家展示如何利用TensorFlow使用(经典)MNIST数据集训练并评 ...

  5. [na]win7系统安装在t450s

    电脑配置 电脑型号 联想 ThinkPad T450s 笔记本电脑(最近买了个ngff口的128g的固态ssd) 操作系统 Windows 旗舰版 64位 主显卡 集成显卡 IE浏览器 版本号 8.0 ...

  6. 【Android】3.19 示例19--全景图HelloWorld

    分类:C#.Android.VS2015.百度地图应用: 创建日期:2016-02-04 百度全景图是一种实景地图服务.为用户提供城市.街道和其他环境的360度全景图像,用户可以通过该服务获得如临其境 ...

  7. Freemarker-2.3.22 Demo - No01_获取模板并直接输出

    package No01_获取模板并直接输出; import java.io.File; import java.io.FileOutputStream; import java.io.OutputS ...

  8. PairRDD中算子foldByKey图解

    foldByKey 函数原型: def foldByKey(zeroValue: V)(func: (V, V) => V): RDD[(K, V)] def foldByKey(zeroVal ...

  9. JS转换HTML转义符,防止javascript注入攻击,亲测可用

    function removeHtmlTab(tab) {  return tab.replace(/<[^<>]+?>/g,'');//删除所有HTML标签 } functi ...

  10. centos启动zookeeper

    切换到zookeeper的bin目录下,执行 ./zkServer.sh start