unix-timestamp

Get current NSDate in timestamp format

亡梦爱人 提交于 2019-11-29 18:50:26
I have a basic method which gets the current time and sets it in a string. However, how can I get it to format the current date & time in a UNIX since-1970 timestamp format? Here is my code: NSDate *currentTime = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"hh-mm"]; NSString *resultString = [dateFormatter stringFromDate: currentTime]; Is it possible to use NSDateFormatter to change the 'resultString' into a timestamp? Here's what I use: NSString * timestamp = [NSString stringWithFormat:@"%f",[[NSDate date] timeIntervalSince1970]

How to convert timestamps to dates in Bash?

∥☆過路亽.° 提交于 2019-11-29 18:36:19
I need a shell command or script that converts a Unix timestamp to a date. The input can come either from the first parameter or from stdin, allowing for the following usage patterns: ts2date 1267619929 and echo 1267619929 | ts2date Both commands should output "Wed Mar 3 13:38:49 2010". On later versions of common Linux distributions you can use: date -d @1267619929 rafaelzlisboa date -r <number> works for me on Mac OS X. This version is similar to chiborg's answer, but it eliminates the need for the external tty and cat . It uses date , but could just as easily use gawk . You can change the

How to Convert UNIX epoc time to Date and time in ios swift

穿精又带淫゛_ 提交于 2019-11-29 18:10:54
I'm trying to convert the UNIX epoc time to datetime format using the below code var epocTime = NSTimeInterval(1429162809359) let myDate = NSDate(timeIntervalSince1970: epocTime) println("Converted Time \(myDate)") the actual result is (Thu, 16 Apr 2015 05:40:09 GMT) but am getting something like (47258-05-14 05:15:59 +0000) Can anyone please tel me how to achieve this. update: Xcode 8.2.1 • Swift 3.0.2 You need to convert it from milliseconds dividing it by 1000: let epocTime = TimeInterval(1429162809359) / 1000 let myDate = Date(timeIntervalSince1970: epocTime) // "Apr 16, 2015, 2:40 AM"

How to convert Human readable timestamp to Unix timestamp by using PowerShell?

蹲街弑〆低调 提交于 2019-11-29 15:44:36
I have a following csv file format, which contains some tool information and normal time. "Tool","TimeRaised" "Abod","27-Jun-14 8:32:45 AM" "Test","27-Jun-14 8:30:42 AM" "Groupd","27-Jun-14 8:22:01 AM" "Tize","27-Jun-14 8:15:50 AM" "COrd","27-Jun-14 8:00:52 AM" I want to convert that normal time to Unix timestamp format by using PowerShell cmdlet. But I dont know which powershell cmdlet to use. PS > Get-Date -date "27-Jun-14 8:00:52 AM" -UFormat %s 1403856052 来源: https://stackoverflow.com/questions/24467492/how-to-convert-human-readable-timestamp-to-unix-timestamp-by-using-powershell

When do we chose DateTime over Timestamp

柔情痞子 提交于 2019-11-29 14:55:08
问题 As I spend most of my time with php and mysql or pgsql, I will use DateTime as a generic word for the date API. In php there is no "Date", "Time", "DateTime" and "DateTimeOffset" As I develop web application more and more elaborate, I use DateTime most of time, but sometimes I wonder if it is really what I want. for example it happens that I just want to display the today's date (for example when I want to store a forum or blog post), there is no calculation, no filter to provide, no

Minimal implementation of gmtime algorithm?

南楼画角 提交于 2019-11-29 14:42:39
Does anyone know of a simple gmtime or ctime implementation without consideration for timezone, no external dependencies, and a non-copyleft license (BSD/MIT/anything proprietary-safe)? Preferably in C, but basically anything that gives me the algorithm in its minimal form would work. I just need seconds since "Jan 1, 1970 00:00:00" broken down into year, day, month, hr, min, sec. And it's almost time to go home on a Friday so I'm feeling a bit lazy. Try newlib http://sourceware.org/newlib/ it is a BSD license. It is designed for embedded systems, so tends to be quite small and simple. Look at

How to convert “YYYY-MM-DD hh:mm:ss” to UNIX timestamp in Java?

我与影子孤独终老i 提交于 2019-11-29 12:55:41
Or, maybe you know a better approach how to solve this problem. I get dates in the format of "YYYY—MM-DD HH:MM:SS" and need to calculate time difference between now then in approximate increments: 1 minute ago, 1 hour ago, etc. Any pointers much appreciated :) phisch Have a look at the SimpleDateFormat . You can define your pattern and parse it into a Java Date Object: SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = format.parse("your string goes here"); long timestamp = date.getTime(); The first line defines the SimpleDateFormat (can also be static if you

Best practice for storing the date in MySQL from PHP

与世无争的帅哥 提交于 2019-11-29 11:25:36
问题 I've been using the unix timestamp all my life. I like it because it's easy to compare, it's fast because I store it as an integer. And since I'm using PHP, I can get any date/time format with date() function from the unixtimestamp. Now, some people are saying that it's best to use the DATETIME format. But besides the more suited name, I don't see any advantages. Is it indeed better to use DATETIME, if so, what are the advantages? Thanks. 回答1: If you store dates as Unix timestamps in the

How to convert date time into unix epoch value in Postgres?

别说谁变了你拦得住时间么 提交于 2019-11-29 10:50:49
问题 How do I convert the following format to UNIX timestamps? A value like: 01-02-2015 10:20 PM should be converted to: 1418273999000 I did try to_timestamp function but its not working for me. 回答1: If your data is stored in a column called ts, in a table called data, do this: select extract(epoch from ts) from data 回答2: To add Joe's answer, you can use date_part , i think it's syntax is clearer than 'extract'. select date_part('epoch', ts) from data; 来源: https://stackoverflow.com/questions

UNIX date: How to convert week number to a date range (Mon-Sun)?

让人想犯罪 __ 提交于 2019-11-29 10:05:09
I have list of week numbers extracted from huge log file, they were extracted using syntax: $ date --date="Wed Mar 20 10:19:56 2012" +%W; 12 I want to create a simple bash function which can convert these week numbers to a date range. I suppose function should accept 2 arguments: $number and $year, example: $ week() { ......... } $ number=12; year=2012 $ week $number $year "Mon Mar 19 2012" - "Sun Mar 25 2012" With GNU date : $ cat weekof.sh function weekof() { local week=$1 year=$2 local week_num_of_Jan_1 week_day_of_Jan_1 local first_Mon local date_fmt="+%a %b %d %Y" local mon sun week_num