|
Actually you're dead wrong in so many ways.
1) Since ToString() and Parse() both use the *same* culture, it doesn't matter what that culture is.
2) The culture used is not necessarily the system default. It is the current culture, which can be set programmatically to whatever we'd like it to be.
3) The default culture doesn't actually depend on where the machine is located.
I once wrote a disposable class called CultureBubble in order to easily run portions of code with a specific culture, like this:
using (new CultureBubble("FR"))
{
foo();
bar();
}
This technique is quite useful, as it requires minimal coding compared to writing logic for dealing with different cultures everywhere data is parsed or presented in culture-dependent ways.
|
|
|
|
|
Ha,
I come from a Java background so my first thought was "What's wrong with it"
I switched over to .NET about 7 years ago. so now I would write it like this:
DateTime.Now.Date.ToShortDateString()
|
|
|
|
|
7 years of .NET experience and you don't see what's wrong with it? Or is there a joke in there that I'm missing? (Monday morning, brain not fully engaged yet)
|
|
|
|
|
Drink some coffee, it was a joke
|
|
|
|
|
Actually
DateTime date = DateTime.Parse(DateTime.Now.Date.ToString("dd/MM/yyyy"));
can be written as
DateTime date = DateTime.Now.Date;
No strings involved! You'll also notice that the original coder acutally had the "DateTime.Now.Date" bit, which they then cast to a string (in UK date format) that is subsequently parsed back to a DateTime.
|
|
|
|
|
In some parts of the world the original statement and yours will not yield the same result.
And the original may throw an exception, yours wouldn't. So we need to see the specs first.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Well spotted. Have some brick points.
|
|
|
|
|
TimeSpan keyDays = new TimeSpan(this.FooLicenceKeyHolder.FooLicence.Licence.LicenceExpiryDate.Ticks);
TimeSpan nowDays = new TimeSpan(System.DateTime.Now.Ticks);
int daysLeft = keyDays.Days - nowDays.Days;
|
|
|
|
|
LOL. That example makes me want to fold.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
Chris Meech wrote: makes me want to fold.
Head-slamming the desk is a form of folding, not?
(but seriously, that code still exists in our code base, not wrong, but funny )
|
|
|
|
|
For a moment there I thought you were measuring your licence expiry in ticks.
"This evaluation licence will expire in 342,827,400 nanoseconds."
|
|
|
|
|
Yep, that takes the biscuit. What's the conversion rate of Idiotions into Imbiciles (our local dim-wit currency)?
|
|
|
|
|
Simply amazing! Thanks for sharing, I had a good laugh.
|
|
|
|
|
My jaw hurts from having it smack the desktop.
|
|
|
|
|
keefb wrote: I still can't work out why
As to why, he only wants the date, with the time portion set to 0.
Marc
Will work for food.
Interacx
I'm not overthinking the problem, I just felt like I needed a small, unimportant, uninteresting rant! - Martin Hart Turner
|
|
|
|
|
And I should add the simplest version is:
DateTime.Today
Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)
|
|
|
|
|
Not good but I've seen worse.
I'm sitting in front of code that's full of...
try
{
// various code here
}
catch
{
}
finally
{
}
Empty catch and finally blocks everywhere.
In your case though I think that will break if regional language settings define the date format as anything other than date/month/year as it'll format it with the date first and then reparse it as say mm/dd/yyyy in the US causing the date and month to be swapped.
|
|
|
|
|
I just ran across this line of condition in a KeyUp handler.
if ((e.Modifiers.GetHashCode().ToString() + "+" + e.KeyCode.GetHashCode().ToString()) == "131072+39")
|
|
|
|
|
It could be worse. They could then split the generated string by the "+", convert each element to a float, and ask if the value is 131072. Then if it is, repeat the process with the second element using a nested if-statement.
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
... so that's the way to do it
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Of course. I can't think of any 'better' way to obfuscate make it version-dependant write it
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
I remember one program which wanted to check if two variables were equal to something like 73 and 89, in either order, so rather than testing whether (var1=73 and var2=89) or (var1=89 and var2=73) it tested whether var*var2=6497. Not sure whether that qualifies as brilliant or horrible. The two variables were bytes, and the constants were primes, so the factorization was unique.
|
|
|
|
|
supercat9 wrote: Not sure whether that qualifies as brilliant or horrible. The two variables were bytes, and the constants were primes, so the factorization was unique.
I'd go with horrible. Because they are bytes, the multiplication test relies on an implicit conversion to (at least) int16. Future failure coming up!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I'd go with horrible. Because they are bytes, the multiplication test relies on an implicit conversion to (at least) int16. Future failure coming up!
I can't see a problem there, since I don't know of any language which wouldn't do at least an 8x8->16 multiply. A more interesting problem would arise if the constants changed so the factorization was no longer unique.
|
|
|
|
|
Brilliant if documented by a comment that they must be primes. Otherwise Horror.
JustAStupidGurl
|
|
|
|