Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 valtteri_m · Aug 11, 2014 at 02:29 PM · javascripttimedaynightday

Check what day of the week it is

So I have this day night cycle script that works on your computers time, and I was wondering if there's a way for it to know what day it is too? like Monday and stuff

the code: #pragma strict

 var color1 : Color = Color.red;
 var color2 : Color = Color.blue;
 
 var Day : Light;
 var Night : Light;
 
 var dt = Date();
 
 var timetext : GUIText;
  
 function Update () {
  
 var day = dt.Now.Day.ToString();
  
 var month = dt.Now.Month.ToString();
  
 var year = dt.Now.Year.ToString();
  
 var hours = dt.Now.Hour.ToString();
         
 var minutes = dt.Now.Minute.ToString();
  
     if (parseInt(minutes) < 10) minutes = "0" + minutes;
  
 var seconds = dt.Now.Second.ToString();
  
     if(parseInt(seconds) < 10) seconds = "0" + seconds;
 
 timetext.text = day + "/" + month + "/" + year + "   " + hours + ":" + minutes + ":" + seconds;
 
 if(parseInt(hours) > 19)
 {
     Day.enabled = false;
     Night.enabled = true;
     camera.backgroundColor = color2;
 }
     
 if(parseInt(hours) < 7)
 {
     Day.enabled = false;
     Night.enabled = true;
 }
         
 if(parseInt(hours) < 19)
 {
     Day.enabled = true;
     Night.enabled = false;
     camera.backgroundColor = color1;
 }
             
 if(parseInt(hours) > 7)
 {
     Day.enabled = true;
     Night.enabled = false;
 }
 }


Comment
Add comment · Show 1
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 robertbu · Aug 11, 2014 at 02:35 PM 0
Share

http://msdn.microsoft.com/en-us/library/system.datetime(v=vs.110).aspx

3 Replies

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

Answer by HarshadK · Aug 11, 2014 at 02:32 PM

Here's a c# function: dateValue.DayOfWeek

If you want to code it then you can find required logic, formula with explanation here: Determination of the day of the week

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 valtteri_m · Aug 11, 2014 at 05:42 PM 0
Share

id prefer java.. is there for java?

avatar image HarshadK · Aug 12, 2014 at 01:41 PM 0
Share

It does work with javascript also.

This is the demo code for using it:

 import System;
 
 function Start () {
     var dt: DateTime = new DateTime(2003, 5, 1);
     Debug.Log(dt.DayOfWeek);
 }

You need to use 'import System' specified at the top for this to work.

avatar image valtteri_m · Aug 13, 2014 at 05:04 PM 0
Share

thanks it works c: heres a question though, what does the 2003, 5, 1 mean?

avatar image HarshadK · Aug 13, 2014 at 05:50 PM 0
Share

It is just the values for year, month, and day. Nothing much. :-)

avatar image
-1

Answer by Slipmike00 · Oct 07, 2018 at 11:28 AM

// Update is called once per frame void Update () {

     day = (int)System.DateTime.Now.Day;

}

Comment
Add comment · Show 1 · 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 Bunny83 · Oct 07, 2018 at 02:14 PM 0
Share

No, just no. The Day property returns the day of the month. Also this question has already been answered four years ago. The question specifically asked for the DayOfWeek

avatar image
0

Answer by AdnanSiddique · Dec 30, 2021 at 07:06 AM

i want to detect is it a Sunday or not ? it is so simple, just follow the below line of code

if(System.DateTime.Now.DayOfWeek == System.DayOfWeek.Sunday)

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

6 People are following this question.

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

Related Questions

Day Night Cycle Script Not Working? 1 Answer

How to make GUI Text appear after a certain amount of time 2 Answers

javascript System time and date? 3 Answers

Timed event Question 2 Answers

How to make Scene darker to look more like night time. 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