How get DateTime.Now with “AM” not “ق.ظ”
up vote
1
down vote
favorite
I try to get DateTime.Now , but what I get is:
'23/05/2016 03:16:51 ق.ظ'
I want to have
'23/05/2016 03:16:51 AM'
or something like this
c# datetime
add a comment |
up vote
1
down vote
favorite
I try to get DateTime.Now , but what I get is:
'23/05/2016 03:16:51 ق.ظ'
I want to have
'23/05/2016 03:16:51 AM'
or something like this
c# datetime
6
You can useDateTime.Now.ToString(string Format)
, and specify what format you want. Check MSDN for applicable formats.
– raidensan
May 23 '16 at 12:01
2
DateTime.Now.ToString(new CultureInfo("en-US"))
– Tim Schmelter
May 23 '16 at 12:07
Or possiblyCultureInfo.InvariantCulture
, depending on the context.
– Matthew Watson
May 23 '16 at 12:09
1
@raidensan That isn't enough. OP ought to specify the culture in this case.
– Sriram Sakthivel
May 23 '16 at 12:11
@SriramSakthivel then, there is a catch here. If I recall correctly the first output is from Persian calendar. If OP wants to just change the AM/PM specifier of Persian culture, he can change these from System Regional settings or, by specifying CultureInfo of app. I highly suspect that OP useDateTime.Now
without giving any format at all.
– raidensan
May 23 '16 at 12:18
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I try to get DateTime.Now , but what I get is:
'23/05/2016 03:16:51 ق.ظ'
I want to have
'23/05/2016 03:16:51 AM'
or something like this
c# datetime
I try to get DateTime.Now , but what I get is:
'23/05/2016 03:16:51 ق.ظ'
I want to have
'23/05/2016 03:16:51 AM'
or something like this
c# datetime
c# datetime
edited Nov 10 at 15:05
Cœur
16.9k9102139
16.9k9102139
asked May 23 '16 at 11:59
ara
3716
3716
6
You can useDateTime.Now.ToString(string Format)
, and specify what format you want. Check MSDN for applicable formats.
– raidensan
May 23 '16 at 12:01
2
DateTime.Now.ToString(new CultureInfo("en-US"))
– Tim Schmelter
May 23 '16 at 12:07
Or possiblyCultureInfo.InvariantCulture
, depending on the context.
– Matthew Watson
May 23 '16 at 12:09
1
@raidensan That isn't enough. OP ought to specify the culture in this case.
– Sriram Sakthivel
May 23 '16 at 12:11
@SriramSakthivel then, there is a catch here. If I recall correctly the first output is from Persian calendar. If OP wants to just change the AM/PM specifier of Persian culture, he can change these from System Regional settings or, by specifying CultureInfo of app. I highly suspect that OP useDateTime.Now
without giving any format at all.
– raidensan
May 23 '16 at 12:18
add a comment |
6
You can useDateTime.Now.ToString(string Format)
, and specify what format you want. Check MSDN for applicable formats.
– raidensan
May 23 '16 at 12:01
2
DateTime.Now.ToString(new CultureInfo("en-US"))
– Tim Schmelter
May 23 '16 at 12:07
Or possiblyCultureInfo.InvariantCulture
, depending on the context.
– Matthew Watson
May 23 '16 at 12:09
1
@raidensan That isn't enough. OP ought to specify the culture in this case.
– Sriram Sakthivel
May 23 '16 at 12:11
@SriramSakthivel then, there is a catch here. If I recall correctly the first output is from Persian calendar. If OP wants to just change the AM/PM specifier of Persian culture, he can change these from System Regional settings or, by specifying CultureInfo of app. I highly suspect that OP useDateTime.Now
without giving any format at all.
– raidensan
May 23 '16 at 12:18
6
6
You can use
DateTime.Now.ToString(string Format)
, and specify what format you want. Check MSDN for applicable formats.– raidensan
May 23 '16 at 12:01
You can use
DateTime.Now.ToString(string Format)
, and specify what format you want. Check MSDN for applicable formats.– raidensan
May 23 '16 at 12:01
2
2
DateTime.Now.ToString(new CultureInfo("en-US"))
– Tim Schmelter
May 23 '16 at 12:07
DateTime.Now.ToString(new CultureInfo("en-US"))
– Tim Schmelter
May 23 '16 at 12:07
Or possibly
CultureInfo.InvariantCulture
, depending on the context.– Matthew Watson
May 23 '16 at 12:09
Or possibly
CultureInfo.InvariantCulture
, depending on the context.– Matthew Watson
May 23 '16 at 12:09
1
1
@raidensan That isn't enough. OP ought to specify the culture in this case.
– Sriram Sakthivel
May 23 '16 at 12:11
@raidensan That isn't enough. OP ought to specify the culture in this case.
– Sriram Sakthivel
May 23 '16 at 12:11
@SriramSakthivel then, there is a catch here. If I recall correctly the first output is from Persian calendar. If OP wants to just change the AM/PM specifier of Persian culture, he can change these from System Regional settings or, by specifying CultureInfo of app. I highly suspect that OP use
DateTime.Now
without giving any format at all.– raidensan
May 23 '16 at 12:18
@SriramSakthivel then, there is a catch here. If I recall correctly the first output is from Persian calendar. If OP wants to just change the AM/PM specifier of Persian culture, he can change these from System Regional settings or, by specifying CultureInfo of app. I highly suspect that OP use
DateTime.Now
without giving any format at all.– raidensan
May 23 '16 at 12:18
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
Then you current culture seems to be an arabic one. You can use the overload of DateTime.ToString
:
var enUsCulture = new CultureInfo("en-US");
string result = DateTime.Now.ToString( enUsCulture );
an an alternative you could pass the exact format with CultureInfo.InvariantCulture
(to avoid that /
will be replaced with your current culture's date separator):
string result = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
The InvariantCulture
avoids that the "/" custom format specifier
will cause /
to be replaced with your current culture's date separator.
"To be sure":DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
– Corak
May 23 '16 at 12:13
1
Not the invariant culture?
– stuartd
May 23 '16 at 12:16
@stuartd: no, it does not use theAM/PM
designator. But i've used a different approach whereInvariantCulture
would be useful to supress the the"/" custom format specifier
– Tim Schmelter
May 23 '16 at 12:24
thank you very much :)
– ara
May 23 '16 at 12:47
add a comment |
up vote
0
down vote
You could create a specific CultureInfo with your requirements starting from the CurrentCulture
CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.LCID);
ci.DateTimeFormat.AMDesignator = "AM";
ci.DateTimeFormat.PMDesignator = "PM";
ci.DateTimeFormat.LongTimePattern = "HH:mm:ss tt";
string result = DateTime.Now.ToString(ci);
Console.WriteLine(result);
thank you , it works too, but I had one way to choose
– ara
May 23 '16 at 12:48
add a comment |
up vote
0
down vote
I think CultureInfo.InvariantCulture is the key here
DateTime now = DateTime.Now;
string result = now.ToString("dd MMM yyyy hh:mm tt", CultureInfo.InvariantCulture);
Console.WriteLine(result);
This should give you "23 May 2016 02:32 PM", you can further edit the date and time by using other setting in the string format specifier. But keep InvarianCulture and tt in order to recieve AP/PM.
For all possible formats and some examples check these links
https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
http://www.dotnetperls.com/datetime-format
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Then you current culture seems to be an arabic one. You can use the overload of DateTime.ToString
:
var enUsCulture = new CultureInfo("en-US");
string result = DateTime.Now.ToString( enUsCulture );
an an alternative you could pass the exact format with CultureInfo.InvariantCulture
(to avoid that /
will be replaced with your current culture's date separator):
string result = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
The InvariantCulture
avoids that the "/" custom format specifier
will cause /
to be replaced with your current culture's date separator.
"To be sure":DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
– Corak
May 23 '16 at 12:13
1
Not the invariant culture?
– stuartd
May 23 '16 at 12:16
@stuartd: no, it does not use theAM/PM
designator. But i've used a different approach whereInvariantCulture
would be useful to supress the the"/" custom format specifier
– Tim Schmelter
May 23 '16 at 12:24
thank you very much :)
– ara
May 23 '16 at 12:47
add a comment |
up vote
1
down vote
accepted
Then you current culture seems to be an arabic one. You can use the overload of DateTime.ToString
:
var enUsCulture = new CultureInfo("en-US");
string result = DateTime.Now.ToString( enUsCulture );
an an alternative you could pass the exact format with CultureInfo.InvariantCulture
(to avoid that /
will be replaced with your current culture's date separator):
string result = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
The InvariantCulture
avoids that the "/" custom format specifier
will cause /
to be replaced with your current culture's date separator.
"To be sure":DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
– Corak
May 23 '16 at 12:13
1
Not the invariant culture?
– stuartd
May 23 '16 at 12:16
@stuartd: no, it does not use theAM/PM
designator. But i've used a different approach whereInvariantCulture
would be useful to supress the the"/" custom format specifier
– Tim Schmelter
May 23 '16 at 12:24
thank you very much :)
– ara
May 23 '16 at 12:47
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Then you current culture seems to be an arabic one. You can use the overload of DateTime.ToString
:
var enUsCulture = new CultureInfo("en-US");
string result = DateTime.Now.ToString( enUsCulture );
an an alternative you could pass the exact format with CultureInfo.InvariantCulture
(to avoid that /
will be replaced with your current culture's date separator):
string result = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
The InvariantCulture
avoids that the "/" custom format specifier
will cause /
to be replaced with your current culture's date separator.
Then you current culture seems to be an arabic one. You can use the overload of DateTime.ToString
:
var enUsCulture = new CultureInfo("en-US");
string result = DateTime.Now.ToString( enUsCulture );
an an alternative you could pass the exact format with CultureInfo.InvariantCulture
(to avoid that /
will be replaced with your current culture's date separator):
string result = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
The InvariantCulture
avoids that the "/" custom format specifier
will cause /
to be replaced with your current culture's date separator.
edited May 23 '16 at 12:22
answered May 23 '16 at 12:09
Tim Schmelter
357k44448705
357k44448705
"To be sure":DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
– Corak
May 23 '16 at 12:13
1
Not the invariant culture?
– stuartd
May 23 '16 at 12:16
@stuartd: no, it does not use theAM/PM
designator. But i've used a different approach whereInvariantCulture
would be useful to supress the the"/" custom format specifier
– Tim Schmelter
May 23 '16 at 12:24
thank you very much :)
– ara
May 23 '16 at 12:47
add a comment |
"To be sure":DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
– Corak
May 23 '16 at 12:13
1
Not the invariant culture?
– stuartd
May 23 '16 at 12:16
@stuartd: no, it does not use theAM/PM
designator. But i've used a different approach whereInvariantCulture
would be useful to supress the the"/" custom format specifier
– Tim Schmelter
May 23 '16 at 12:24
thank you very much :)
– ara
May 23 '16 at 12:47
"To be sure":
DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
– Corak
May 23 '16 at 12:13
"To be sure":
DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.GetCultureInfo("en-US"))
– Corak
May 23 '16 at 12:13
1
1
Not the invariant culture?
– stuartd
May 23 '16 at 12:16
Not the invariant culture?
– stuartd
May 23 '16 at 12:16
@stuartd: no, it does not use the
AM/PM
designator. But i've used a different approach where InvariantCulture
would be useful to supress the the "/" custom format specifier
– Tim Schmelter
May 23 '16 at 12:24
@stuartd: no, it does not use the
AM/PM
designator. But i've used a different approach where InvariantCulture
would be useful to supress the the "/" custom format specifier
– Tim Schmelter
May 23 '16 at 12:24
thank you very much :)
– ara
May 23 '16 at 12:47
thank you very much :)
– ara
May 23 '16 at 12:47
add a comment |
up vote
0
down vote
You could create a specific CultureInfo with your requirements starting from the CurrentCulture
CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.LCID);
ci.DateTimeFormat.AMDesignator = "AM";
ci.DateTimeFormat.PMDesignator = "PM";
ci.DateTimeFormat.LongTimePattern = "HH:mm:ss tt";
string result = DateTime.Now.ToString(ci);
Console.WriteLine(result);
thank you , it works too, but I had one way to choose
– ara
May 23 '16 at 12:48
add a comment |
up vote
0
down vote
You could create a specific CultureInfo with your requirements starting from the CurrentCulture
CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.LCID);
ci.DateTimeFormat.AMDesignator = "AM";
ci.DateTimeFormat.PMDesignator = "PM";
ci.DateTimeFormat.LongTimePattern = "HH:mm:ss tt";
string result = DateTime.Now.ToString(ci);
Console.WriteLine(result);
thank you , it works too, but I had one way to choose
– ara
May 23 '16 at 12:48
add a comment |
up vote
0
down vote
up vote
0
down vote
You could create a specific CultureInfo with your requirements starting from the CurrentCulture
CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.LCID);
ci.DateTimeFormat.AMDesignator = "AM";
ci.DateTimeFormat.PMDesignator = "PM";
ci.DateTimeFormat.LongTimePattern = "HH:mm:ss tt";
string result = DateTime.Now.ToString(ci);
Console.WriteLine(result);
You could create a specific CultureInfo with your requirements starting from the CurrentCulture
CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.LCID);
ci.DateTimeFormat.AMDesignator = "AM";
ci.DateTimeFormat.PMDesignator = "PM";
ci.DateTimeFormat.LongTimePattern = "HH:mm:ss tt";
string result = DateTime.Now.ToString(ci);
Console.WriteLine(result);
answered May 23 '16 at 12:20
Steve
178k16149216
178k16149216
thank you , it works too, but I had one way to choose
– ara
May 23 '16 at 12:48
add a comment |
thank you , it works too, but I had one way to choose
– ara
May 23 '16 at 12:48
thank you , it works too, but I had one way to choose
– ara
May 23 '16 at 12:48
thank you , it works too, but I had one way to choose
– ara
May 23 '16 at 12:48
add a comment |
up vote
0
down vote
I think CultureInfo.InvariantCulture is the key here
DateTime now = DateTime.Now;
string result = now.ToString("dd MMM yyyy hh:mm tt", CultureInfo.InvariantCulture);
Console.WriteLine(result);
This should give you "23 May 2016 02:32 PM", you can further edit the date and time by using other setting in the string format specifier. But keep InvarianCulture and tt in order to recieve AP/PM.
For all possible formats and some examples check these links
https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
http://www.dotnetperls.com/datetime-format
add a comment |
up vote
0
down vote
I think CultureInfo.InvariantCulture is the key here
DateTime now = DateTime.Now;
string result = now.ToString("dd MMM yyyy hh:mm tt", CultureInfo.InvariantCulture);
Console.WriteLine(result);
This should give you "23 May 2016 02:32 PM", you can further edit the date and time by using other setting in the string format specifier. But keep InvarianCulture and tt in order to recieve AP/PM.
For all possible formats and some examples check these links
https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
http://www.dotnetperls.com/datetime-format
add a comment |
up vote
0
down vote
up vote
0
down vote
I think CultureInfo.InvariantCulture is the key here
DateTime now = DateTime.Now;
string result = now.ToString("dd MMM yyyy hh:mm tt", CultureInfo.InvariantCulture);
Console.WriteLine(result);
This should give you "23 May 2016 02:32 PM", you can further edit the date and time by using other setting in the string format specifier. But keep InvarianCulture and tt in order to recieve AP/PM.
For all possible formats and some examples check these links
https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
http://www.dotnetperls.com/datetime-format
I think CultureInfo.InvariantCulture is the key here
DateTime now = DateTime.Now;
string result = now.ToString("dd MMM yyyy hh:mm tt", CultureInfo.InvariantCulture);
Console.WriteLine(result);
This should give you "23 May 2016 02:32 PM", you can further edit the date and time by using other setting in the string format specifier. But keep InvarianCulture and tt in order to recieve AP/PM.
For all possible formats and some examples check these links
https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
http://www.dotnetperls.com/datetime-format
answered May 23 '16 at 12:30
NoobPointerException
16111
16111
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37390425%2fhow-get-datetime-now-with-am-not-%25d9%2582-%25d8%25b8%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
6
You can use
DateTime.Now.ToString(string Format)
, and specify what format you want. Check MSDN for applicable formats.– raidensan
May 23 '16 at 12:01
2
DateTime.Now.ToString(new CultureInfo("en-US"))
– Tim Schmelter
May 23 '16 at 12:07
Or possibly
CultureInfo.InvariantCulture
, depending on the context.– Matthew Watson
May 23 '16 at 12:09
1
@raidensan That isn't enough. OP ought to specify the culture in this case.
– Sriram Sakthivel
May 23 '16 at 12:11
@SriramSakthivel then, there is a catch here. If I recall correctly the first output is from Persian calendar. If OP wants to just change the AM/PM specifier of Persian culture, he can change these from System Regional settings or, by specifying CultureInfo of app. I highly suspect that OP use
DateTime.Now
without giving any format at all.– raidensan
May 23 '16 at 12:18