unix-timestamp

Convert a unix timestamp to a human readable date in PHP?

南楼画角 提交于 2019-12-01 14:57:49
问题 I have a timestamp value from PHP: 1188604800000 When I format the time to human readable like this: date("m/d/Y", 1188604800000) It prints: 05/21/39635 If I put the number into an online Unix Timestamp converter I get: Sat, 01 Sep 2007 00:00:00 GMT What am I doing wrong? 回答1: PHP uses seconds-based timestamps, so divide 1188604800 by 1000 and you are good. php> echo date('Y-m-d', 1188604800000/1000); 2007-09-01 回答2: I was having trouble with my date being one day off and I had to manually

get the unix timestamp from type 1 uuid

不问归期 提交于 2019-12-01 08:11:58
In our java application we are trying to get the unix time from the type 1 uuid. But its not giving the correct date time values. long time = uuid.timestamp(); time = time / 10000L; // Dividing by 10^4 as its in 100 nanoseconds precision Calendar c = Calendar.getInstance(); c.setTimeInMillis(time); c.getTime(); Can some one please help ? Edit: Fixed the divisor(10^4) From the docs for timestamp() : The resulting timestamp is measured in 100-nanosecond units since midnight, October 15, 1582 UTC. So you need to offset it from that. For example: Calendar uuidEpoch = Calendar.getInstance(TimeZone

convert unix timestamp php

99封情书 提交于 2019-12-01 07:36:47
I have a database that stores the time for me. I insert it from PHP using date( 'Y-m-d H:i:s'); I then use this function to convert it to a unix timestamp in PHP function convert_datetime($str) { list($date, $time) = explode(' ', $str); list($year, $month, $day) = explode('-', $date); list($hour, $minute, $second) = explode(':', $time); $timestamp = mktime($hour, $minute, $second, $month, $day, $year); return $timestamp; } What I now need to do is convert this timestamp to the date and time in this format: yyyymmddhhmmss (without any hyphens, dashes, colons, etc). Has anyone any ideas? You can

convert unix timestamp php

我的未来我决定 提交于 2019-12-01 06:09:30
问题 I have a database that stores the time for me. I insert it from PHP using date( 'Y-m-d H:i:s'); I then use this function to convert it to a unix timestamp in PHP function convert_datetime($str) { list($date, $time) = explode(' ', $str); list($year, $month, $day) = explode('-', $date); list($hour, $minute, $second) = explode(':', $time); $timestamp = mktime($hour, $minute, $second, $month, $day, $year); return $timestamp; } What I now need to do is convert this timestamp to the date and time

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

馋奶兔 提交于 2019-12-01 04:10:01
How can I convert a time in the format "YYYY-MM-DD hh:mm:ss" (e.g. "2011-07-15 13:18:52" ) to a UNIX timestamp? I tried this piece of Javascript code: date = new Date("2011-07-15").getTime() / 1000 alert(date) And it works, but it results in NaN when I add time('2011-07-15 13:18:52') to the input. Use the long date constructor and specify all date/time components: var match = '2011-07-15 13:18:52'.match(/^(\d+)-(\d+)-(\d+) (\d+)\:(\d+)\:(\d+)$/) var date = new Date(match[1], match[2] - 1, match[3], match[4], match[5], match[6]) // ------------------------------------^^^ // month must be

Getting file modification time on UNIX using utime in C

江枫思渺然 提交于 2019-12-01 02:58:00
I have been told by a professor that you can get a file's last modification time by using utime.h . However, the man page seem to cite that utime() only sets this value. How can I look up the last time a file was changed in C on a UNIX system? This returns the file's mtime , the "time of last data modification". Note that Unix also has a concept ctime , the "time of last status change" (see also ctime, atime, mtime ). #include <sys/types.h> #include <sys/stat.h> time_t get_mtime(const char *path) { struct stat statbuf; if (stat(path, &statbuf) == -1) { perror(path); exit(1); } return statbuf

How do I find the unix timestamp for the start of the next day in php?

血红的双手。 提交于 2019-12-01 02:22:56
I have a unix timestamp for the current time. I want to get the unix timestamp for the start of the next day. $current_timestamp = time(); $allowable_start_date = strtotime('+1 day', $current_timestamp); As I am doing it now, I am simply adding 1 whole entire day to the unix timestamp, when instead I would like to figure out how many seconds are left in this current day, and only add that many seconds in order to get the unix timestamp for the very first minute of the next day. What is the best way to go about this? The most straightforward way to simply " make " that time: $tomorrowMidnight =

Why do I need to multiply unix timestamps by 1000 in JavaScript?

风格不统一 提交于 2019-12-01 02:09:01
I'm sure there's a reason I have to add three zeros to every Unix timestamp in JavaScript in order to get the correct date. Can you tell me why? Is it as simple as milliseconds since the epoch vs. seconds? Because Javascript uses milliseconds internally, while normal UNIX timestamps are usually in seconds. Javascript uses the number of milliseconds since epoch. Unix timestamp is seconds since epoch. Hence, the need to convert Unix timestamp into millseconds before using it in Javascript Unix time is the number of seconds since the epoch (1 Jan 1970). In Javascript, the Date object expects the

Joda DateTime to Unix DateTime

核能气质少年 提交于 2019-12-01 02:06:26
It's odd enough, but I didn't find any result about converting Joda(Time) DateTime to Unix DateTime (or timestamp, whichever is the correct name). How can I do this? Any object that inherits from BaseDateTime (including DateTime ) has the method public long getMillis() According to the API it: Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z. So a working example to get the seconds would simply be: new DateTime().getMillis() / 1000 For completeness, the definition of the Unix Timestamp according to Wikipedia : Unix time, or POSIX time, is a system for

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

♀尐吖头ヾ 提交于 2019-12-01 00:57:17
问题 How can I convert a time in the format "YYYY-MM-DD hh:mm:ss" (e.g. "2011-07-15 13:18:52" ) to a UNIX timestamp? I tried this piece of Javascript code: date = new Date("2011-07-15").getTime() / 1000 alert(date) And it works, but it results in NaN when I add time('2011-07-15 13:18:52') to the input. 回答1: Use the long date constructor and specify all date/time components: var match = '2011-07-15 13:18:52'.match(/^(\d+)-(\d+)-(\d+) (\d+)\:(\d+)\:(\d+)$/) var date = new Date(match[1], match[2] - 1