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
4
Question by HolBol · Aug 05, 2010 at 11:16 AM · timesystem

How to get system time?

Is there anyway i can get the time of day from the system, and if so how?

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

1 Reply

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

Answer by jashan · Aug 05, 2010 at 11:19 AM

Yes:

DateTime.Now

For this to work, you need to have the namespace that provides DateTime available. There's a few options. You could use the fully qualified class name which includes the namespace. So that would be:

System.DateTime.Now

Or, at the beginning of your file, you could add a using directive:

C#

using System;

UnityScript/JavaScript:

import System;

For full documentation of DateTime, see API documentation of DateTime on MSDN

Comment
Add comment · Show 6 · 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 HolBol · Aug 05, 2010 at 12:28 PM 0
Share

Doesn't work, i get error "unknown identifier 'DateTime'

avatar image jashan · Aug 05, 2010 at 12:45 PM 0
Share

DateTime is in the System namespace, so you might have to include that. In C#, that's done via using System; in the beginning of your file. I'll check out how that's handled in UnityScript real quick and then edit the answer.

avatar image jashan · Aug 05, 2010 at 01:27 PM 0
Share

Ok, updated the answer with quite a bit more info ;-)

avatar image HolBol · Aug 06, 2010 at 07:33 AM 0
Share

With this, can i just get the time, and not the date, and then convert the time so like 11:30 is 11.5, 1:45 is 13.75?

avatar image jashan · Aug 06, 2010 at 01:52 PM 0
Share

You could probably do something like DateTime.Now.ToString("HH:mm"); to get only the current time. You might still need an extra parameter, like DateTime.Now.ToString("HH:mm", CultureInfo.InvariantCulture); in which case you'd also have to import System.Globalization (check out the doc of the ToString()-method of DateTime, that should give you all you need). That might also give you your "special formats", maybe (but I never needed that, so I can't say much about it).

Show more comments

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

Smaller Time Interval? 3 Answers

Game structure: Time intervals, enemy speed, enemy quantity. How best to set this up? 1 Answer

javascript System time and date? 3 Answers

check time since player last played the game ? 1 Answer

Accessing local system ( File Browser ) 2 Answers


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