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
Related
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
intl: ^0.16.1
Can't seem to parse HTTP header date field with flutter DateFormat/HttpDate
here is what I tried:
var date = HttpDate.parse("Thu, 11 Feb 2021 10:53:15 +0200");
return error:
Invalid HTTP date Thu, 11 Feb 2021 10:53:15 +0200
Note: the string was received by package:googleapis/gmail/v1.dart
final zFormatDateEmailRFC2822 = DateFormat("EEE, d MMM yyyy HH:mm:ss Z");
var date = zFormatDateEmailRFC2822.parse("Thu, 11 Feb 2021 10:53:15 +0200");
return error:
Trying to read EEE from Thu, 11 Feb 2021 10:53:15 +0200 at position 0
The following is an example from https://api.flutter.dev/flutter/intl/DateFormat-class.html
final fmt = DateFormat('EEE, MMM d, ''yy');
var date = fmt.parse("Wed, Jul 10, '96");
return error:
Trying to read EEE from Wed, Jul 10, '96 at position 0
final fmt = DateFormat("d MMM yyyy");
var date = fmt.parse("11 Feb 2021");
return error:
Trying to read MMM from 11 Feb 2021 at position 3
final fmt = DateFormat("MMM");
var date = fmt.parse("Feb");
return error:
Trying to read LLL from Feb at position 0
The only thing that works for me is:
var dateStr = "Thu, 11 Feb 2021 10:53:15 +0200";
RegExp regExp = RegExp(r"(.*, \d+ .* \d+ \d+:\d+:\d+)");
if (regExp.hasMatch(dateStr)) {
var groups = regExp.firstMatch(dateStr);
var date = HttpDate.parse(groups[1] + " GMT");
print("date $date >${HttpDate.format(date)}<");
}
Try it:
final fmt = DateFormat("d MMM yyyy", "en_US");
var date = fmt.parse("11 Feb 2021");
I had to parse the email header date string
Somehow the other answers where not considering everything i needed and so i came up with the following solution which also takes care of the timezone +0200
DateFormat('E, d MMM yyyy hh:mm:ss Z', 'en_US').parse(DATE_STRING);
Input String : Wed, 18 Aug 2021 09:00:43 +0200
DateTime.toISo8601String() => 2021-08-18T09:00:43.000
DateTime.toUTC().toString() => 2021-08-18 07:00:43.000Z
If you want to learn more about the patterns please have a look at DateFormat
I am having a string which contains 24 hr format.
I am trying to convert it to 24hrs format but it is not changing. below is my code.
$fromtime = '2018-03-28,23:37:50'
[datetime]$fromtime24hrFormat = ([datetime]$fromtime).ToString("yyyy-MM-dd,HH:mm:ss")
$fromtime24hrFormat
Wednesday, March 28, 2018 11:37:50 PM
It shows in PM which is correct. But is it not possible to show it in 24 hr format?
You're so close!
$fromtime = '2018-03-28,23:37:50'
[datetime]$fromtime24hrFormat = ([datetime]$fromtime)
$fromtime24hrFormat.ToString("yyyy-MM-dd,HH:mm:ss")
The problem is that your last line was effectively just dumping the datetime object to the output; which will use a default formatting.
Did you want to add AM/PM to the original input? Try:
$fromtime = '2018-03-28,23:37:50'
$fromtime24hrFormat = [datetime]$fromtime
$fromtime24hrFormat.ToString("yyyy-MM-dd,HH:mm:ss tt")
2018-03-28,23:37:50 p.m.
"p.m." vs PM is caused by my Norwegian regional settings
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")
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.