Skip to main content

How to convert String To DateTime In Unity C#

How to fetch Day, Month or year from date time string?
How to get Hour, minute or second from a date time string?

Following snippet of code can be used to deal with most of the forms of date time string in Unity C#
Instead of having time in the form of
  "2020-1-31 12:10:15" 
you can also pass
"31/1/2020 12:10:15 PM"

and or any such case of Date time in string.
Then from this DateTime object you can fetch any particular detail like Year shown in example below.


System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
DateTime tempDate = Convert.ToDateTime("2020-5-6 12:10:15", culture);
Debug.Log("Testing date time conversion: " + tempDate.Year);



This could be used to deal with date time strings of the form 
 "dd:MM:yyyy HH:mm:ss"
"yyyy:MM:dd HH:mm:ss"

Comments

Popular posts from this blog

How to delete Hot Apps folder on Oppo Realme

Bloat wares are the single worst enemy of anyone who just wants a simple experience with the mobile phones. Oppo goes to a next level in spamming stuff we don't need by their Hot Apps shortcut on Homescreen. And it is not always available in a new phone but comes after few hours sometimes days of usage. To disable this icon/folder/shortcut follow the steps below. 1. Open Settings. Swipe down the notification bar and open settings. 2. Open OPPO AppStore settings. Scroll all the way down and click OPPO AppStore. 3. Disable Homescreen folder for hot apps. That's it. You can also disable notification alert from App Store and Browser for even better Android experience as these apps spam a lot.

How to add custom domain for Blogspot

If you are having trouble trying to setup your custom domain with your blogspot blog, you have come to the right place. If you haven't noticed this blog runs on Blogspot as well. I had so much trouble trying to setup my custom domain myself. The guide given by Google itself here Link: https://support.google.com/blogger/answer/1233387?visit_id=1-636146283785501872-108692412&p=customdomain&hl=en&rd=2 is good enough but is really confusing. Reason being lack of guiding images. But fear not I am here to solve this problem for you. If you are not in mood of learning something new today and are in hurry to just setup your domain skip the information part and follow the images to setup your domain. Do you know how does a website work? How does it shows the content as it shows? Here's a short version. We take a name, a domain name and point it to a place in some server. It is same as opening any file location in you computer. Only difference is we use a...

How to fix clothes flickering in Unreal Engine 5.

 This issue can be noticed some of the character clothes when using Paragon Characters in UE5. To fix the flickering issue, Use Self Collisions checkbox in collisions properties under the Static Mesh option of your character. Open the character model go to   Asset Details > Clothing Properties - Cloth Config - ChaosClothConfig - Collision Properties - Use Self Collisions > False