unix-timestamp

Convert string time to UNIX timestamp

戏子无情 提交于 2019-12-04 04:08:10
I have a string like 2013-05-29T21:19:48Z . I'd like to convert it to the number of seconds since 1 January 1970 (the UNIX epoch), so that I can save it using just 4 bytes (or maybe 5 bytes, to avoid the year 2038 problem). How can I do that in a portable way? (My code has to run both on Linux and Windows.) I can get the date parts out of the string, but I don't know how to figure out the number of seconds. I tried looking at the documentation of date and time utilities in C++ , but I didn't find anything. use std::get_time if you want the c++ way - but both other options are also valid.

Elegantly check if a given date is yesterday

主宰稳场 提交于 2019-12-04 01:25:06
Assuming you have a Unix timestamp, what would be an easy and/or elegant way to check if that timestamp was some time yesterday? I am mostly looking for solutions in Javascript, PHP or C#, but pseudo code and language agnostic solutions (if any) are welcome as well. PHP: $isYesterday = date('Ymd', $timestamp) == date('Ymd', strtotime('yesterday')); In C# you could use this: bool isYesterday = DateTime.Today - time.Date == TimeSpan.FromDays(1); In pseudo code, to compare timestamps: get current Unix timestamp transform the retrieved timestamp to a date subtract 1 day from the date transform the

AngularJS UnixTime to DateTime Format with date filter failed

爱⌒轻易说出口 提交于 2019-12-04 00:23:06
I learned that one can transform a unix time stamp into a date by using date filter from this post: AngularJS. Convert tag value (Unix time to human-readable time) But I can not convert mine with it... <td>{{contract.start_date_unix | date:'MM-dd-yyyy'}}</td> inside the contract.start_date_unix , its valued at 1406779200 I checked it with a checker that it shows exactly what I want: Thu, 31 Jul 2014 04:00:00 GMT (but of course, the format I want is MM-dd-yyyy, the date is correct and that's what I try to prove here) But when I do the date filter above, it will only show 01-17-1970 or 01-16

How to write bigint (timestamp in milliseconds) value as timestamp in postgresql

流过昼夜 提交于 2019-12-04 00:14:07
I'm trying to store in timestamp with timezone field my value. It is in milliseconds from 1970. select TO_CHAR(TO_TIMESTAMP(1401432881230), 'DD/MM/YYYY HH24:MI:SS.MS') Expected 30/5/2014 11:29:42 10:54:41.230 , but get 22/08/46379 23:27:02.000 Unix timestamps measures time with seconds, and not milliseconds ( almost everywhere, in PostgreSQL too). Therefore you need to call SELECT TO_TIMESTAMP(1401432881230 / 1000); If you want to preserve milliseconds, call with double precision : SELECT TO_TIMESTAMP(1401432881230::double precision / 1000); This is how I convert ms to timestamp and keep ms

Converting date/time string to unix timestamp in MySQL

谁说我不能喝 提交于 2019-12-03 23:06:50
We have a database with all the dates and times stored in one column called timestamp. The format of the date/time in the column "timestamp" is as: 03 Aug 08:10am. I would like to convert this (03 Aug 08:10am) to UNIX TIMESTAMP in MySQL and not PHP because we already have over 500 rows with this format: 03 Aug 08:10am. I tried create a new INT column called new_timestamp and ran this query: UPDATE table_name SET new_timestamp = UNIX_TIMESTAMP(timestamp); However, it shows that 0 rows were affected. This is not a duplicate, don't redirect me to how to convert in PHP. Read the question first :)

How to decompose unix time in C

荒凉一梦 提交于 2019-12-03 20:08:34
This seems like something no one should ever have to do, but I'm working on a kernel module for an embedded system (OpenWRT) in which it seems that time.h does include the timespec and time_t types, and the clock_gettime and gmtime functions, but does not include localtime , ctime , time , or, critically, the tm type. When I attempt to cast the return pointer from gmtime to my own struct, I get a segfault. So I guess I'd be content to solve the problem either of two ways—it'd be great to figure out how to get access to that missing type, or alternatively, how to roll my own method for

group by month of unix timestamp field

心已入冬 提交于 2019-12-03 17:22:53
问题 I'm trying to get my code to output in the following format: january 2012 - 34 february 2012 - 23 where 34 and 23 would be a count of the total rows that fall within that month that have the id_dealership of 7. I need this to output all data for every month that an assignment was ever made. The assignments table structure is as follows: id_dealer (int) date_assigned (int) I've tried this but it does not work at all: SELECT MONTH(date_assigned), YEAR(date_assigned), COUNT(*) FROM assignments

How to represent dates before epoch as a UNIX timestamp

强颜欢笑 提交于 2019-12-03 11:56:02
问题 It occurred to me that I'm not aware of a mechanism to store dates before 1970 jan. 1 as Unix timestamps. Since that date is the Unix "epoch" this isn't much of a surprise. But - even though it's not designed for that - I still wish to store dates in the far past in Unix format. I need this for reasons. So my question is: how would one go about making unix-timestamps contain "invalid" but still working dates? Would storing a negative amount of seconds work? Can we even store negative amounts

Convert Unix timestamp into datetime

我们两清 提交于 2019-12-03 10:41:00
问题 I have the following data frame > head(try) creates time 1 128.29508 1417392072 3 236.98361 1417392072 7 98.45902 1417392072 9 157.44068 1417392131 10 227.38333 1417392131 11 242.03390 1417392131 > str(try) 'data.frame': 102968 obs. of 2 variables: $ creates: num 128.3 237 98.5 157.4 227.4 ... $ time : Factor w/ 26418 levels "1417392071","1417392072",..: 2 2 2 3 3 3 3 3 5 5 ... I am unable to convert the UNIX timestamp into datetime using the following methods I tried > head(as.POSIXlt(as

Same datetime across timezones in browser - on a booking engine

北慕城南 提交于 2019-12-03 08:23:34
I'm looking for the best practice/solution to book a service internationally, using same time in any browser. I don't quite get the logic (and dug around here too). Use case user in Brussels booking lets say a haircut service based in Singapore - he is flying there in a week. He picks 14:00 in the browser datetime control. The browser is, however, set to +1 UTC. SG haircut stylist should see the time in his agenda as 14:00 SG time. the barber shop owner is traveling at Dubai, and he wants to see his agenda still in SG timezone, despite his browser is temporarily set to +4 UTC. Basically, all