I feel like this is something I've done a thousand times so not sure why it is being so difficult now. I've created a method that simply returns Today's date for the user based on their UTC offset. But instead of returning a string resembling a date, it is returning this garbage
"䙭/䙭/Ἰ뻱䙭"
Here is the code.
public string getToday(Context context)
{
var settings = PreferenceManager.GetDefaultSharedPreferences(context);
var offset = settings.GetInt("offset", -5);
var now = DateTime.UtcNow.AddHours(offset);
return now.ToShortDateString();
}
When I step into the code using a breakpoint, offset and now both seem correct. now contains valid date parts all appearing to be accurate. Something about converting now to a string seems to go horribly wrong. Also tried:
return now.ToString("MM/dd/yyyy");
Same result. Weird part is the below code in another activity works without issue
var offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours;
var now = DateTime.UtcNow.AddHours(offset);
now.ToString("MM-dd-yyyy")
Sounds to me like a localization issue. Make sure you're actually in English, be it en-US or similar.
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