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
1
Question by HolBol · Aug 20, 2010 at 01:23 AM · timedate

getting julian date in unity?

how can i use unity to convert the a date in the format dd/mm to it's day number [or julian dare]? so like july 3rd would be day 184 when it's not a leap year etc

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
0

Answer by Shah Mansur · May 11, 2014 at 08:48 AM

First of all Day Number number is not Julian Day

Day Number is very basic, DateTime class of C# provides you with Day Of Year which is total number of days since the start of current year and leap-year phenomenon is handled within the class, see the MSDN Documentation.

All you need to do is add System library to your code

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class myClass: MonoBehaviour {
 
 void Start () {
     Debug.Log(DateTime.Now.DayOfYear.toString());
 }
 
 void Update(){
 }

 }

And as far as Julian Day is concerned, it is number of total days since the beginning of Julian Period.

Julian Period started at January 1, 4713 BC 12:00:00 hrs. So you need to calculate total number of days since Jan-1,4713 BC for that take the difference between the Year (Current or any) and 4713 BC. Count total number of leap years within that period.

 Julian Day = ( Difference of Years * 365 ) + NumberOfLeapYearsInThisPeriod

What this will do is add 1 day for all leap years.

Julian Date is more precise than Julian Day and is in decimal representing how much of a day has passed, remember that Julian Period started at January 1, 4713 BC 12:00:00 hrs at noon, meaning Julian day starts & ends on mid day.

For today May-11,2014 Julian Day is 2456788. Which is true before noon 12:00 hrs after that the Julian Day is +1 which is 2456789. So you need to write algo to which considers 24 hrs as 1, 12 hours = 0.5. And so and so forth calculations down to milliseconds.

For May 11, 2014 11:00:00 hrs the Julian Date is 2456788.95833

Supposing we already have Julian Day, heres the code for Julian Date

     int julianDay; //let's suppose we have value of Julian Day here
     float julianDate;
     now = DateTime.Now;
     int mSecs = (((now.Hour * 60) + now.Minute) * 60 + now.Second) * 1000 + now.Millisecond;
     julianDate = (mSecs < 43200000) ? --julianDay + (mSecs/43200000) : julianDay + (mSecs-43200000)/86400000;

Explanation is a day has 86400000 milliseconds and at mid day 43200000 millisecods. So by dividing time in milliseconds by 86400000 or 43200000 I get decimal portion of day or half day respectively.

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

Get System date 1 Answer

Count time when the game is not running (mobile device)? 2 Answers

Cleaning this code up. 2 Answers

How can I get the time since the epoch date in Unity3D? 2 Answers

putting the date into a variable 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