[Test]
public void Sadness()
{
var dateTime = DateTime.UtcNow;
Assert.That(dateTime, Is.EqualTo(DateTime.Parse(dateTime.ToString())));
}
Failed :
Expected: 2011-10-31 06:12:44.000
But was: 2011-10-31 06:12:44.350
I wish to know what is happening behind the scenes in ToString() etc to cause this behavior.
EDIT After seeing Jon's Answer :
[Test]
public void NewSadness()
{
var dateTime = DateTime.UtcNow;
Assert.That(dateTime, Is.EqualTo(DateTime.Parse(dateTime.ToString("o"))));
}
Result :
Expected: 2011-10-31 12:03:04.161
But was: 2011-10-31 06:33:04.161
Same result with capital and small 'o' . I'm reading up the docs, but still unclear.
Behavior is driven by genetic and environmental factors that affect an individual. Behavior is also driven, in part, by thoughts and feelings, which provide insight into individual psyche, revealing such things as attitudes and values.
They propose three key factors that influence behavior change: Information about the behavior. Motivation to perform the behavior. Behavioral skills to perform the behavior.
The social psychology seeks to understand the causes of human social behaviour. These causes are characteristics and actions of others, cognitive processes, environmental variables, culture, and biological causes.
Strongly rooted in psychology and sociology, studies of human behavior give us an academic understanding of motivations, productivity, and how teams work. In turn, these insights can help make workplaces or any group setting more productive.
Have a look at what dateTime.ToString()
produces - it will typically only be accurate to the second, although it depends on cultural settings. If ToString()
only gives a result accurate to a second, there's no way that parsing the string can give more information...
You can use the "o" standard format string to provide a round-trippable string representation. For example, at the moment it produces something like:
2011-10-31T06:28:34.6425574Z
EDIT: You need to parse with the same specifier to get the same result back:
string text = dateTime.ToString("o");
// Culture is irrelevant when using the "o" specifier
DateTime parsed = DateTime.ParseExact(text, "o", null,
DateTimeStyles.RoundtripKind);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With