游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1263|回复: 0

基本的日期时间字符串格式化测试

[复制链接]

3

主题

137

帖子

151

积分

注册会员

Rank: 2

积分
151
QQ
发表于 2008-4-1 12:00:00 | 显示全部楼层 |阅读模式
闲来无事,乱写一通



  1. #include <ctime>
  2. #include <string>
  3. #include <iostream>

  4. using namespace std;


  5. int main()
  6. {
  7.     time_t tTime;
  8.     time(&tTime);

  9.     tm* tLocalTime;
  10.     tLocalTime = localtime(&tTime);

  11.     const string sSampleTime = "2008-04-01 08:51:10";

  12.     string sTimeFormat = "%Y-%m-%d %H:%M:%S";
  13.     char* spTime = new char[sSampleTime.size()+1]; //+1 是因为char* 需要一个'\0'作为结束符
  14.     strftime(spTime, sSampleTime.size()+1, sTimeFormat.c_str(), tLocalTime);

  15.     cout << spTime << endl;

  16.     delete[] spTime;
  17. }
复制代码


回车和空格都给过滤掉了?faint
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-20 17:26

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表