I have this date from twitter, this represents the exact date the tweet is published,
Sun, 01 Jul 2012 19:05:54 +0000
what I want is to make its format into MM/DD HH:MM, tried to look for php date formats but couldn't find a way to make it look exactly the way I want it to be. Can someone please help? Thanks.
print date('m/d h:i',strtotime('Sun, 01 Jul 2012 19:05:54 +0000'));
The date function for php is a good place to find all sorts of information on this.
This would be pretty simple to search and figure it out. You are looking for a date... ahh, date, that is a php function. When you look that up you will see that it takes some params, a format and a time stamp. Well... You do not have a time stamp you have a string. how do i convert a string to time? Wait, there is a strtotime function in php. There you have it... run the date function in php with the way you want the date to look and then convert the string to timestamp with strtotime
<?php
date_default_timezone_set("UTC");
$string = "Sun, 01 Jul 2012 19:05:54 +0000";
$timestamp = strtotime($string);
print "Date is " . date("m/d H:i", $timestamp) . "\n";
?>
You may have to change timezone, and/or add/subtract seconds or use local time functions to convert between TZ's.
Related
I am getting some results from a weather API and one of that is date in epoch time stamp.
I found that converting with Date(timeIntervalSince1970:) I get the right date
I am using the specific number --> 1501452000 and I get 2 results on Playground
1) Jul 31,2017,12:00AM. -- when --> let date = Date(timeIntervalSince1970: 1501452000)
2) 2017-07-30 22:00:00 +0000 when --> print(date)
API results are :
"time_epoch": 1501452000,
"time": "2017-07-30 23:00",
By checking the rest of my results they are matching with the rest of the API results....... but when I convert 1501452000 -> to date I don't get the correct Hour 23:00 but 22:00 !
Any idea what is happening ?
is it wrong the API( I don't think so ) or the way I am converting it?
Thanks a lot
The timeIntervalSince1970 initializer sets up the time in the UTC timezone, while your API might be sending dates in GMT. When you are using print(data), you have different results, because if you are not using a DateFormatter to generate the String format of the Date object, it uses your devices current settings when formatting the Date object.
A Date object represents an absolute point in time, but when you are printing it with a DateFormatter, it gets converted into a location/time zone specific, relative representation. You just have to set up your DateFormatter to match the time zone settings of your API and you will see the dates correctly printed.
This issue happens on daylight saving times. Is your country changing daylight saving on this exact date?
let date = Date(timeIntervalSince1970: 1501452000) in Playgrounds should give you the time in your system's timezone when you see it on the right hand side.
When you print it and see 2017-07-30 22:00:00 +0000- this is the same timestamp in GMT
Is the API showing a particular time zone? It looks like GMT+1
I have created a tweet using Twitters REST API. The returned JSON from Twitter from the created Tweet is in this format
'Tue Jan 31 11:15:15 +0000 2017'
Darts
DateTime.parse('Tue Jan 31 11:15:15 +0000 2017');
won't parse this format. I turned to the intl package holds some hope in dealing with this. I try to use DateFormat to solve this thus
DateFormat format = new DateFormat("EEE MMM dd HH:mm:ss ZZZZ yyyy");
format.parse('Tue Jan 31 11:15:15 +0000 2017');
It fails. The only way I can get it to work is to remove the timezone part of the twitter date string
'Tue Jan 31 11:15:15 2017'
and do the following
var date = 'Tue Jan 31 11:15:15 +0000 2017'.split(' ');
date.removeAt(4);
DateFormat format = new DateFormat("EEE MMM dd HH:mm:ss yyyy");
format.parse(date.join(' '));
How can I parse a Twitter datetime string without removing the timezone info part?
It looks like package:intl doesn't support timezones yet: https://github.com/dart-lang/intl/issues/128
You could add your use case to the issue (it shouldn't be much work or require extra data to support the 'ZZZZ' case, since you just need to parse a number), or even better, submit a Pull Request!
Dart DateTime doesn't support timezones, so it's not that useful to parse them. Also, Intl is probably not the best way to parse a string like this. The point of Intl date parsing is that it varies by locale. If you want to parse a fixed format it can be done more easily and more efficiently.
Since DateTime doesn't support time zones, if you want to use that information, it seems like your best bet is to remove it, get the information, and then add that to the time after the fact.
If you're running in the browser, you could also call out to the JS Date.parse(), which does handle that format.
I am trying to convert a date in format (yyyy-mm-dd) to a textual date format like Monday 21 Jan 2012 using PHP. I have tried using mktime() function but I'm a novice and I cant figure it out.
Any help will be grealty appreciated.
e.g :- convert 2012-04-27 => Friday 27 April 2012
Thanks.
You can make use of the DateTime class (which is recommended over strtotime):
$date = new DateTime($date_string);
$textual = $date->format("l j M Y");
echo date("l j M Y", strtotime('2012-04-26'));
I am searching to parse this timestamp
2011-05-18T0702:19Z0088
The first part of the string ("2011-05-18T0702:19Z") look like a ISO 8601 UTC Timestamp, but i don't understand last numbers "0088"
Did someone can tell me more about this format ?
William
Actually it doesn't make sense, since Z is indication of UTC time, after which no symbols are allowed in datetime. So it's actually some invalid format.
If you sure that 'Z' corresponds to UTC you can ignore symbols after it, or, better, contact source of this format and ask them for fix.
Now, I also notices there is one more error in format, there is no colon between hours and minutes:
2011-05-18T 0702 :19Z0088
I am getting the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert "2010-01-02 23:28:17 UTC" to Date.
I am using WebORB to transfer data between Rails and Flex. The data coming from Rails is of type: 'ActiveSupport::TimeWithZone'. I am trying to assign it to a Flex 'Date' data type.
What am I missing?
From the documentation: http://www.adobe.com/livedocs/flex/3/langref/Date.html#Date()
If you pass a string to the Date class constructor, the date can be in a variety of formats, but must at least include the month, date, and year. For example, Feb 1 2005 is valid, but Feb 2005 is not. The following list indicates some of the valid formats:
Day Month Date Hours:Minutes:Seconds GMT Year (for instance, "Tue Feb 1 00:00:00 GMT-0800 2005", which matches toString())
I think in Rails, what you need to do is calling strftime to format the date output that's going to be sent to Flex
time_with_zone.strftime("%a %b %d %H:%M:%S %z %Y") # => "Sun Jan 03 20:58:16 +0700 2010"
Thanks for the help but, oddly, that wasn't it. Your help, Sikachu, did put me on the right track. I couldn't simply assign the returned result--I had to feed it into the constructor. So, instead of doing this, which didn't work:
var flexDate:Date = server_result.date;
I did this, which works:
var flexDate:Date = new Date(server_result.date);