formatting date from twitter response Zend Framework - zend-framework

im trying to formatting the date field 'created_at' from Twitter API response with Zend_Date. I want output the date like this:
21 of July of 2009, 12:30:00 (for example)
What format is this?:
Fri Oct 23 15:47:42 +0000 2009
thanks a lot

I've had the best luck just doing
$d = new Zend_Date(strtotime($input));
$twitter_format_out = $d->toString('EEE MMM dd HH:mm:ss Z YYY');

These date are not looking a standard format. Therefore, you have to create a format with the right constants (see them here).
Your first example (21 of July of 2009, 12:30:00):
$format = "d ' of ' MMMM ' of ' YYYY, h:mm:ss";
Your second example (Fri Oct 23 15:47:42 +0000 2009):
$format = "EEE MMM d h:mm:ss Z YYYY";
This formats you can use both for importing a date
$date = new Zend_Date($string, $format);
Or for outputting
$date->toString($format);
Look in the manual for locale support etc.

Related

Trouble with converting to Datetime object

I have the below data which is an object type variable named $timestamps
Sat Jan 15 16:21:24
Sat Jan 15 01:31:22
Fri Jan 14 20:58:09
Fri Jan 14 20:51:02
I'm having trouble converting it to Datetime object because of the weird date format. How would you handle this?
I would like it as a datetime object because I plan to convert from current (UTC) to EST.
TIA
You can use the the ParseExact() method provided by the [datetime] class for this:
[datetime]::ParseExact('Fri Jan 14 20:58:09','ddd MMM dd HH:mm:ss',$null)
# returns a - datetime - object of:
# Friday, January 14, 2022 8:58:09 PM
dd - for the day.
MM - for the month.
HH - for the hour - Capitalized for the 24 hour time format.
mm - for the minutes.
ss - for the seconds.
Edit: as suggested by mklement0, we can use [cultureinfo]::InvariantCulture to make the parsing specific to an English date time format. Also, changing dd to d as a more robust solution for days without 2 digits; which should cover both singular, and double digit days.
Seeing $timestamps is an array of strings, you can use a loop (of your choice - in this case the Foreach-Object cmdlet) to iterate through each string parsing the text to return a datetime object:
$timestamps | ForEach-Object {
$culture = [cultureinfo]::InvariantCulture
$format = 'ddd MMM d HH:mm:ss'
$date = [datetime]::ParseExact($_,$format,$culture,'AssumeUniversal, AdjustToUniversal')
[System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($date, 'Eastern Standard Time')
}
Using 'AssumeUniversal, AdjustToUniversal' ensures a UTC output.
Assuming from your comment that you'd like to do a conversion to Eastern Time, passing the newly created datetime object to [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId() with an argument of the desired time zone, you can get your result in the new time zone.
When using $null, the CultureInfo object that corresponds to the current culture is used.
The DateTime.ParseExact() method is probably what you're looking for.
PS C:\TEMP>$timestamp = 'Sat Jan 15 16:21:24'
PS C:\TEMP>$format = 'ddd MMM dd HH:mm:ss'
PS C:\TEMP>[datetime]::ParseExact($timestamp, $format, $null)
Saturday, January 15, 2022 04:21:24 PM
PS C:\TEMP>

in flutter dart convert 1624275605667 into Mon Jun 21 2021 17:10:05 GMT+05:30

var date = 1624275605667;
final DateTime formatted = DateTime(date);
final DateFormat fr = DateFormat('EEE MMM d yyyy HH:mm:ss');
final String dd = fr.format(formatted);
I try like this but getting some type of errors.
I want to convert 1624275605667 into this format Mon Jun 21 2021 17:10:05 GMT+05:30
For this which format I use here
DateFormat('EEE MMM d yyyy HH:mm:ss zzz')
Please try this one
var date = 1624275605667;
final DateTime formatted = DateTime.fromMillisecondsSinceEpoch(date);
final DateFormat fr = DateFormat('EEE MMM dd yyyy HH:mm:ss');
final String dd = fr.format(formatted);
print(dd);
You are using z pattern and it's not implemented yet. Issue is still open since 2015 https://github.com/dart-lang/intl/issues/19
And in intl package already mentioned that this characters are reserved and currently are unimplemented.
For workaround you can use
formatted.timeZoneOffset.toString(); /// 5:30:00.000000
Which is same as GMT+05:30

Date format to show month as text

Struggling with this one. I'm trying to get the below to display like this: 19 Nov 2014
I suppose the real issue here is that I can't find any documentation to get the month to be displayed as text because if I could even get "19 November 2014" then I would just truncate it.
$prevWD = (date)+"$(-1+$(#(1,2-eq7-(date).dayofweek)))"
$prevWD.ToString("dd MM yyyy")
$date = Get-Date -Format "dd MMM yy"
See MS Documentation: Link
Can be done like this:
[datetime]::now.toString("dd MMM yyyy")
Or if you want yesterday:
[datetime]::now.addDays(-1).toString("dd MMM yyyy")
You can try this:
$dt = "{0:d MMM yyyy}" -f (get-date)
write-host $dt

Powershell Convert DateTime to dd mon yyyy

I want to convert a date to this format "dd Mon yyyy".
I have this code which works:
$date = [DateTime]::Parse("21/11/2014")
$dateFormatted = $date.GetDateTimeFormats()[12]
#$dateFormatted displays 21 November 2014
Is there a way to convert it using something like this?:
$dateFormatted = $date.ToString("dd Mon yyyy")
At the moment this returns "21 11on 2014"
I worked it out:
$dateFormatted = $date.ToString("dd MMMM yyyy")

Convert time format 12 de Marzo 2014 05:51 pm

i need to convert date to below spanish format in c#
12 de Marzo 2014 05:51 pm
please suggest
Start here and have a look around the documentation's abundant and useful functions:
http://www.php.net/manual/en/book.datetime.php
Then try:
http://www.php.net/manual/en/function.strftime.php
And sub in your desired language settings with logic/if statements
Is this working for you?
DateTime date = DateTime.Parse("12 de Marzo 2014 05:51 pm");
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Interaction.MsgBox(date.ToLongDateString());
OR
DateTimeFormatInfo espDtfi = new CultureInfo("es-ES", false).DateTimeFormat;
DateTimeFormatInfo usDtfi = new CultureInfo("en-US", false).DateTimeFormat;
string result = Convert.ToDateTime("12 de Marzo 2014 05:51 pm", espDtfi).ToString(usDtfi.ShortDatePattern);
DateTime.Now.ToLongTimeString() // hh:mm:ss xM
DateTime.Now.ToLongDateString() // dayOfTheWeek, Month dd, yyyy