How to convert human-readable date to epoch time?
import datetime# Convert human readable date to epochhuman_readable_date = '2022-09-13 00:00:00'epoch = int(datetime.datetime.strptime(human_readable_date, '%Y-%m-%d %H:%M:%S').timestamp())print(epoch)
// Convert human readable date to epochconst humanReadableDate = '2022-09-13 00:00:00';const epoch = Math.floor(new Date(humanReadableDate).getTime() / 1000);console.log(epoch);
import java.text.SimpleDateFormat;import java.util.Date;// Convert human readable date to epochString humanReadableDate = "2022-09-13 00:00:00";Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(humanReadableDate);long epoch = date.getTime() / 1000;System.out.println(epoch);
using System;// Convert human readable date to epochstring humanReadableDate = "2022-09-13 00:00:00";DateTime date = DateTime.ParseExact(humanReadableDate, "yyyy-MM-dd HH:mm:ss", null);long epoch = (long)(date - new DateTime(1970, 1, 1)).TotalSeconds;Console.WriteLine(epoch);
#include <iostream>#include <chrono>#include <ctime>int main() {// Convert human readable date to epochstd::string humanReadableDate = "2022-09-13 00:00:00";std::tm tm = {};std::istringstream ss(humanReadableDate);ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S");std::time_t epoch = std::mktime(&tm);std::cout << epoch << std::endl;return 0;}
<?php// Convert human readable date to epoch$humanReadableDate = "2022-09-13 00:00:00";$epoch = strtotime($humanReadableDate);echo $epoch;?>
const humanReadableDate = '2022-09-13 00:00:00';const epoch = Math.floor(new Date(humanReadableDate).getTime() / 1000);console.log(epoch);
let humanReadableDate = "2022-09-13 00:00:00"let dateFormatter = DateFormatter()dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"let date = dateFormatter.date(from: humanReadableDate)!let epoch = Int(date.timeIntervalSince1970)print(epoch)
require 'time'# Convert human readable date to epochhuman_readable_date = '2022-09-13 00:00:00'epoch = Time.parse(human_readable_date).to_iputs epoch
package mainimport ("fmt""time")
func main() {// Convert human readable date to epochhumanReadableDate := "2022-09-13 00:00:00"layout := "2006-01-02 15:04:05"t, _ := time.Parse(layout, humanReadableDate)epoch := t.Unix()fmt.Println(epoch)}