Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ruben · Jun 04, 2010 at 09:30 AM · stringformatdatetime

Formatting Date and Time

hi

i have a textfield taking a string representing a specific DateTime format. I want the string representing the DateTime to be formatted as YYYY-MM-DD, how can i do this?

thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Tetrad · Jun 18, 2010 at 04:09 PM

Use DateTime.TryParse.

You'll probably run into issues if you try to overwrite the string the user is typing while they do that, but if you have an input field and a separate display field that shows the "parsed" date time (formatted like Duck's answer) that would work.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
4

Answer by duck · Jun 04, 2010 at 11:34 AM

Is your value coming from an actual DateTime object? If so, you can do this:

yourTextField.text = String.Format("{0:yyyy-MM-dd}", yourDateTimeObj);
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ruben · Jun 04, 2010 at 12:35 PM 0
Share

no my value is com$$anonymous$$g from the text field which is a string

avatar image duck ♦♦ · Jun 04, 2010 at 03:07 PM 0
Share

ok in that case your question isn't very clear. You have it in a string already, and you want it formatted in a different way? What format is it to begin with?

avatar image Cyclops · Jun 04, 2010 at 04:22 PM 0
Share

@Duck, I suspect he means, that a user could enter some random text into a Textfield, and he wants to clean it up. But who knows?

avatar image Ruben · Jun 06, 2010 at 02:48 PM 0
Share

@Cyclops thats what i mean. the user enters a number format for the date (as string) and i want to ensure that its formatted as YYYY-$$anonymous$$$$anonymous$$-DD.

avatar image
0

Answer by FarazKhalid · Jun 02, 2014 at 12:32 PM

 string computerDate;
 string computerTime;
 void computerDateAndTime() // read computer current time and date
     {
         string currentTime=System.DateTime.Now.ToString();
         int z=0;
         string add="";
         for(int i=0;i<currentTime.Length;i++)
         {
             char item = currentTime[i];
             if(item==' ')
             {
                 switch (z)
                 {
                 case 0:
                     computerDate=add;
                     break;
                 case 1:
                     computerTime=add;
                     break;
                 }
                 z++;
                 add="";
             }
             else
             {
                 add+=currentTime[i];
             }
         }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

what package?namespace? do I need to make use of String.Format() for C# programs? 4 Answers

String format to show float as time 3 Answers

Formatting Calendar, Iterating through list of strings. 1 Answer

How to stop WWW from changing request url? 1 Answer

Export objects to a .3DS file at runtime 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges