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 FlashX · Nov 29, 2014 at 03:00 AM · c#time

Find time value between two other time values? C#

Hi all,

Anyone know how to do this in a basic 'Hello World' style?

I'm learning C# and am wanting to basically convert my JS over to C#.

How would i check if todays time is within two set times? Example todays time is 13.30.00 and I'm wanting to check if it is between 10.00.00 and 18.00.00?

Any help would be muchly appreciated!

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

2 Replies

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

Answer by b1gry4n · Nov 29, 2014 at 03:13 AM

Try converting your time to seconds and compare to the other values in seconds.

13.30.00 = 48600 //currentTime = 48600

10.00.00 = 36000 //lowTime = 36000

18.00.00 = 64800 //highTime = 64800

 if(currentTime <= highTime && currentTime >= lowTime){
 //the time is between 10 and 18
 }

if the current time is less than or equal to high time AND the current time is greater than or equal to the low time, the current time is between the high and low time

Comment
Add comment · Show 3 · 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 FlashX · Nov 29, 2014 at 03:19 AM 0
Share

Thanks buddy,

How did you work out the syntax to convert it to seconds?

avatar image b1gry4n · Nov 29, 2014 at 03:29 AM 0
Share

1 hour = 60 $$anonymous$$utes, 1 $$anonymous$$ute = 60 seconds. simple multiplication

 convertToSeconds = ((hour * 60) * 60) + ($$anonymous$$ute * 60) + (seconds)
avatar image FlashX · Nov 29, 2014 at 03:32 AM 0
Share

Thanks bro! You've been a big help! :)

avatar image
0

Answer by FlashX · Nov 29, 2014 at 06:21 AM

I'm back again,

I'm having trouble getting it to read as an int and not a string:

 private int currentHour = System.DateTime.Now.ToString("hh");

Ive tried a couple of things but can't work it out.

Any ideas?

Thanks again

Comment
Add comment · Show 2 · 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 SuperMasterBlasterLaser · Nov 29, 2014 at 06:59 AM 0
Share

ToString function will always return string value and you trying to assign it to int.

avatar image FlashX · Nov 29, 2014 at 07:49 AM 0
Share

Thanks Super$$anonymous$$asterBlasterLaser,

Ive tried removing the "ToString" element however I'm too noobish to get the gist as to how to work it. Would you $$anonymous$$d showing me the syntax? $$anonymous$$y head hurts Lol!

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

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Help with a faster clock? 1 Answer

Get System date 1 Answer

Cleaning this code up. 2 Answers

C# Make something happen for X amount of Seconds. 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