1. 程式人生 > >C++ 將指定的標準時間轉換成時間戳

C++ 將指定的標準時間轉換成時間戳

所使用的的標頭檔案如下:

#include "iostream"
#include "time.h"
#include "string.h"

using namespace std;

程式碼如下:

int standard_to_stamp(char *str_time)  
{  
	struct tm stm;  
	int iY, iM, iD, iH, iMin, iS;  

	memset(&stm,0,sizeof(stm));  
	iY = atoi(str_time);  
	iM = atoi(str_time+5);  
	iD = atoi(str_time+8);  
	iH = atoi(str_time+11);  
	iMin = atoi(str_time+14);  
	iS = atoi(str_time+17);  

	stm.tm_year=iY-1900;  
	stm.tm_mon=iM-1;  
	stm.tm_mday=iD;  
	stm.tm_hour=iH;  
	stm.tm_min=iMin;  
	stm.tm_sec=iS;  

	printf("%d-%0d-%0d %0d:%0d:%0d\n", iY, iM, iD, iH, iMin, iS);   //標準時間格式例如:2016:08:02 12:12:30
	return (int)mktime(&stm);  
}  

int main()
{
	int stampTime = standard_to_stamp("2016:08:02 12:12:30");
	cout << stampTime << endl;

	return 0;
}

注:裡面的atoi(s+5); +8、+11、+14、+17表示的是傳入引數的格式中每個數字距離字串開頭的長度;

執行結果如下:


相關推薦

C++ 指定標準時間轉換時間

所使用的的標頭檔案如下: #include "iostream" #include "time.h" #include "string.h" using namespace std; 程式碼如下

js時間轉換時間10位

var oldTime = (new Date("2018/12/23 08:00:20")).getTime()/1000; alert(oldTime); 延伸閱讀: 什麼是Unix時間戳(Unix timestamp): Unix時間戳(Unix timestamp),或稱Unix時間

C# DataTable對象轉換XML字符串

summary see lB tex int finally n) exce row /// <summary> /// 將DataTable對象轉換成XML字符串 /// </summary>

Python3基礎 str translate 指定字符轉換另一種特定字符

default charm strong .py 實踐 lock right fault pycha ? python : 3.7.0 OS : Ubuntu 18.04.1 LT

c# 陣列或集合 轉換以逗號分隔的字串

class Program     {         static void Main(string[] args)         {             List<string> list = new List<string>();    

時間選擇器的時間轉換時間

// 日期改變 dateChange1:function(date){ // console.log(date) if(this.mark==0){ let dat

C++ 當前系統時間轉換標準格式的時間時間

1:先將系統時間轉換成標準格式的時間,再轉成時間戳 #include "iostream" #include "time.h" #include "string.h" using namespace std; int main() { time_t rawtime ;

標準時間轉換指定格式時間

在Vue專案中 我使用的是 moment.js 安裝 moment.js npm install moment --save 引用JS import moment from ‘moment’ 假如使用的是 element UI的 table元件 <el-table

C#_時間轉換字串的幾種方法

//獲取當前系統時間 DateTime dt = System.DateTime.Now; //將系統時間轉換成字串 string strTime

python時間轉換指定格式的時間

import time, datetime a = datetime.datetime.now() print(str(a)) # '2018-08-19 21:01:42.811262' dete

中國標準時間轉換年月日

var formatDateTime = function (date) { var y = date.getFullYear(); var m = date.getMonth() + 1; m = m < 10 ? ('0' + m) : m; var d = date.get

python 視訊 通過視訊幀轉換時間

def frames_to_timecode(framerate,frames): """ 視訊 通過視訊幀轉換成時間 :param framerate: 視訊幀率 :param frames: 當前視訊幀數 :return:時間(00:00:01:0

格式化後的時間轉換Date型別

原始碼:  var startDate = new Date(document.getElementById("testStartDateFormat").value.replace(/-/g, "/")); //更新上傳圖後的時間格式

中國標準時間轉換YYY-MM-DD

export function changeDate(dateA) { let date; if (dateA) { if (dateA.toString().indexOf('GMT') > -1) { var dateee = new Date(da

PostgreSQL - 怎麼時間轉換

保留原來的毫秒值 select extract(epoch from '03:21:06.678'::time); 這個extract(epoch from )函式得到的是時間是秒單位,如果需要毫秒值就直接乘以1000: select extract(epoch from

伺服器傳來的Long型別的資料轉換時間

//將long轉換成事件格式 long createTime = resultBean.getCreateTime();//資料 Date date = new Date(createTime);//時間管理類 SimpleDat

JSON資料庫中的date欄位轉換時間

問題描述:資料庫中的date欄位:2018-09-01 12:23:23,在Java中取出該欄位,並用FastJSON將其轉化,你就會發現時間變成了148364681324這樣的時間戳,FastJSON提供瞭解決方法。 解決方法:在對應的實體類的的屬性上方定義一

中國標準時間轉換DateTime

string s1 = "Wed Feb 01 2017 00:00:00 GMT+0800".Replace("GMT+0800", ""); string stringValue = Conv

python 視訊 通過視訊幀轉換時間

def frames_to_timecode(framerate,frames): """ 視訊 通過視訊幀轉換成時間 :param framerate: 視訊幀率 :param frames: 當前視訊幀數 :retur

pythonUnix時間轉換時間

將時間戳轉換成時間 在時間戳轉換成時間中,首先需要將時間戳轉換成localtime,再轉換成時間的具體格式: 利用localtime()函式將時間戳轉化成localtime的格式 利用strftime()函式重新格式化時間 #coding:UTF-8