/    Sign up×
Community /Pin to ProfileBookmark

JavaScript and Julian Date

Hi ALL!
I need javascript calendar with regular and julian dates on it, urgent!
Please help.
Something like on this image:

Thank you in advance.

[upl-file uuid=8d19f42a-0fac-4d36-b600-c2bbba096437 size=4kB]Julian date.gif[/upl-file]

to post a comment
JavaScript

28 Comments(s)

Copy linkTweet thisAlerts:
@baldaauthorNov 03.2005 — None? ?
Copy linkTweet thisAlerts:
@gphNov 03.2005 — Here's a julian date function
<i>
</i>Date.prototype.julianDate=function(){
var j=parseInt((this.getTime()-new Date('Dec 30,'+(this.getFullYear()-1)+' 23:00:00').getTime())/86400000).toString(),
i=3-j.length;
while(i--&gt;0)j=0+j;
return j
};

alert(new Date().julianDate())


it's alot easier in vbs

<i>
</i>Function vb_julianDate(date_str)
vb_julianDate = DatePart("y",DateValue(date_str))
End Function

Attached is an image of a modified MS calendar. What do you need it for ?

[upl-file uuid=ce956e25-573e-4301-88e1-b5a249bc4847 size=28kB]calendar.jpg[/upl-file]
Copy linkTweet thisAlerts:
@gphNov 03.2005 — Here's a javascript call to the vbs function I posted
<i>
</i>Date.prototype.month=function(){
return ['January','February','March','April','May','June','July','August','September','October','November','December'][this.getMonth()]
};

Date.prototype.vbDate=function(){
return this.month()+' '+this.getDate()+','+this.getFullYear()
};

var julian_date=vb_julianDate(new Date().vbDate())
Copy linkTweet thisAlerts:
@bokehNov 04.2005 — I don't know what that is above but it certainly has nothing to do with the julian date.

Julian date == The interval of time in days since noon at Greenwich on 1 January 4713 BC

[code=php]<script type="text/javascript">
now = new Date;
alert((now.valueOf()/86400000) + 2440587.5);
</script>[/code]
Copy linkTweet thisAlerts:
@felgallNov 04.2005 — You are getting Julian DAY and Julian DATE mixed up.

Julian DAY == The interval of time in days since noon at Greenwich on 1 January 4713 BC

Julian DATE == The day number within the year counting January 1st as 1 and December 31st as 365 (or 366 in leap years).

To calculate the Julian DAY

<i>
</i>var today = new Date();
var julday = math.Floor((today.valueOf() / (1000 * 60 * 60 * 24)) - 0.5) + 2440588;
Copy linkTweet thisAlerts:
@baldaauthorNov 04.2005 — 2 gph :

Its exactly what I need on your attached image file! Where I can get that MS calendar?

Will it work for web plain html file?
Copy linkTweet thisAlerts:
@bokehNov 04.2005 — You are getting Julian DAY and Julian DATE mixed up.

Julian DAY == The interval of time in days since noon at Greenwich on 1 January 4713 BC

Julian DATE == The day number within the year counting January 1st as 1 and December 31st as 365 (or 366 in leap years).

To calculate the Julian DAY

<i>
</i>var today = new Date();
var julday = math.Floor((today.valueOf() / (1000 * 60 * 60 * 24)) - 0.5) + 2440588;
[/QUOTE]

Not according to wikipedia!

The julian day is as you state above and your code outputs whereas the

Julian date == Julian day number plus the fraction of the day that has elapsed since noon expressed as a decimal, which is exactly what the code I posted returns.

[B]Edit:[/B] More info found elsewhere:

Julian dates (abbreviated JD) are simply a continuous count of days and fractions since noon Universal Time on January 1, 4713 BCE (on the Julian calendar). Almost 2.5 million days have transpired since this date. Julian dates are widely used as time variables within astronomical software. Typically, a 64-bit floating point (double precision) variable can represent an epoch expressed as a Julian date to about 1 millisecond precision.

This demonstrates that a Julian date should be expressed as a float.
Copy linkTweet thisAlerts:
@baldaauthorNov 04.2005 — 2 bokeh:

I also got confused. I do agree with you date must be float, but user says Julian date for example for 11/04/2005 is 308 ?!!?!?What does 308 means I have no idea but

gph's vb and javascript function gives me that number...:-)
Copy linkTweet thisAlerts:
@bokehNov 04.2005 — Day 308 out of 365 of our present year. I don't see the connection with the julian date though.

Use of the word [B]date[/B] is confussing though as it is a measure of time and date all rolled into one.

By the way what are yu going to use the Julian date for?
Copy linkTweet thisAlerts:
@AncoraNov 04.2005 — .....
Copy linkTweet thisAlerts:
@baldaauthorNov 04.2005 — I think they said they using it in scheduling or production... Sorry guys, I have no clue, never used it myself.
Copy linkTweet thisAlerts:
@gphNov 04.2005 — I don't know what that is above but it certainly has nothing to do with the julian date.

Julian date == The interval of time in days since noon at Greenwich on 1 January 4713 BC

[code=php]<script type="text/javascript">
now = new Date;
alert((now.valueOf()/86400000) + 2440587.5);
</script>[/code]
[/QUOTE]


Julian date, atleast in practical application, means the 3 digit numeric day of the year.

Open the hood of a car and look for numbers on the parts, in those numbers will be a 3 digit julian date and a 2 digit year number. This is so car manufacturers and suppliers can trace batches of parts.

Every application written, for industries requiring them, outputs julian [B]date[/B] as a 3 digit number. Jan 1 == 001 and so on

2 gph :

Its exactly what I need on your attached image file! Where I can get that MS calendar?

Will it work for web plain html file?[/QUOTE]


It will work in HTML but is unfortunately an IE only behavior. The original is [url=http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/ie55/VLEBCalendar/default.asp]here[/url]. I just inserted the julian date.
Copy linkTweet thisAlerts:
@bokehNov 04.2005 — Julian date, atleast in practical application, means the 3 digit numeric day of the year.[/QUOTE][URL=http://www.google.com/search?q=julian+date&sourceid=mozilla-search&start=0&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-US:official]Here is a google search for Julian date.[/URL] I have been down five levels and still can't find a mention of such a use. The number you are refering to is just the day of the year and certainly has no relationship with the julian date.
Copy linkTweet thisAlerts:
@bokehNov 04.2005 — Open the hood of a car and look for numbers on the parts, in those numbers will be a 3 digit julian date and a 2 digit year number. This is so car manufacturers and suppliers can trace batches of parts.[/QUOTE]
What you are talking about here is part of [B]ISO 8601:1988[/B] and called the ordinal date format, represented as follows:

1993045 or 1993-045 (complete representation)

93045 or 93-045

-045

and also is nothing to do with the Julian date.
Copy linkTweet thisAlerts:
@baldaauthorNov 05.2005 — 2 gph:

Could you please post you complete code with MS Calendar?

I hope I did not asked too much. :-)

Thank you.
Copy linkTweet thisAlerts:
@gphNov 05.2005 — [url=http://www.google.ca/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=%22julian+date%22+industry&btnG=Search]another google search[/url]
Copy linkTweet thisAlerts:
@gphNov 05.2005 — Ok balda, I'll attach it because it's rather large. Give me an hour or so to convert to html and remove client specific stuff
Copy linkTweet thisAlerts:
@bokehNov 05.2005 — [url=http://www.google.ca/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=%22julian+date%22+industry&btnG=Search]another google search[/url][/QUOTE]If you search the key term [URL=http://www.google.ca/search?hs=fgV&hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=%22julian+date%22+&btnG=Search&meta=]Julian date[/URL] you won't see that errornous use. You will instead find 675,000 pages with the correct use.
Copy linkTweet thisAlerts:
@baldaauthorNov 05.2005 — 2 gph:

Thank you, I'll be looking forward to it.

I am really appreciate you time.
Copy linkTweet thisAlerts:
@gphNov 05.2005 — If you search the key term [URL=http://www.google.ca/search?hs=fgV&hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=%22julian+date%22+&btnG=Search&meta=]Julian date[/URL] you won't see that errornous use. You will instead find 675,000 pages with the correct use.[/QUOTE]
I freelance for a company that has hundreds of plants in dozens of countries. They call it julian date, so does their suppliers and all the auto manufacturers they supply.

Clearly, from the search I posted, this naming is not limited to the auto industry. So if you're right, millions are wrong.

It is not my place to speak for these millions of people. If you are sure they've all got it wrong then I suggest you take it up with the people that use it. You can probably start with the nearest factory to you that date stamps their products.

balda, I included an htm file and the hta in the image I previously posted. The hta is only useful offline. Incase anyone missed my previous post, this only works in IE.

[upl-file uuid=b7565214-c5c0-4182-ab94-38827db7540e size=12kB]calendar.zip[/upl-file]
Copy linkTweet thisAlerts:
@baldaauthorNov 05.2005 — gph,

Thank you again, man!
----------------------------------


Thank you all guys for valued input.
Copy linkTweet thisAlerts:
@felgallNov 05.2005 — There are millions of offline references that define the Julian Date as the day number within a given year. That wikipedia and google results show differently just demonstrates that there are a lot of people who don't know the difference.
Copy linkTweet thisAlerts:
@bokehNov 05.2005 — There are millions of offline references that define the Julian Date as the day number within a given year. That wikipedia and google results show differently just demonstrates that there are a lot of people who don't know the difference.[/QUOTE]So which source would you accept?

Encyclopaedia Britanica?

Encarta?

Sky and Telescope?

Are they all wrong as well?
Copy linkTweet thisAlerts:
@LHookerJun 23.2009 — I did not get a julian date (i.e.

Julian DATE == The day number within the year counting January 1st as 1 and December 31st as 365 (or 366 in leap years). The code is below. Thanks ! ! !


<HTML>

<HEAD></HEAD>

<BODY bgcolor="CFFFF">

<script type="text/javascript">

var today = new Date();

var julday = math.Floor((today.valueOf() / (1000 * 60 * 60 * 24)) - 0.5) + 2440588;

alert julday

</script>

</BODY>

</HTML>
Copy linkTweet thisAlerts:
@felgallJun 23.2009 — So which source would you accept?

Encyclopaedia Britanica?

Encarta?

Sky and Telescope?

Are they all wrong as well?[/QUOTE]


Yes if they don't mention the most common value that people mean when they refer to Julian Date - which is CCYYDDD (so today is 2009174).

The Julian day is of course 2455006.
Copy linkTweet thisAlerts:
@mrhooJun 23.2009 — [CODE]Date.prototype.toJulian= function(fixed){
var D= this.toUTCArray(), F= Math.floor;

var year= D[0], month= D[1]+1, date= D[2],
hr= D[3], min= D[4], sec= D[5];

var a= Math.abs(month-9), g= 1, jd, j1, v= 1;

if(year<= 1585) g= 0;
if((month-9)< 0) v= -1;
hr= hr+(min/60)+ (sec/3600);

j1= -1*F((F((F(year+v*F(a/7)))/100)+ 1)*3/4);
jd= -1*F(7*(F((month+9)/12)+ year)/4);
jd= jd+F(275*month/9)+date+(g*j1);
jd=( jd+1721027+2*g+367*year-.5)+(hr/24);

if(typeof fixed== 'number') return jd.toFixed(fixed);
return fixed===true? jd: F(jd);
}

Date.prototype.toUTCArray= function(){
var D= this;
return [D.getUTCFullYear(), D.getUTCMonth(),
D.getUTCDate(), D.getUTCHours(),D.getUTCMinutes(),
D.getUTCSeconds(), D.getUTCMilliseconds()];
}[/CODE]


[B]alert((new Date()).toJulian());[/B]

[CODE]Date.prototype.getDayofYear= function(){
var d= new Date(this).setMonth(0, 0);
return Math.round((this-d)/86400000);
}[/CODE]
[B]

alert((new Date()).getDayofYear()+'-'+((new Date()).getFullYear()+'').substring(2));[/B]
Copy linkTweet thisAlerts:
@bokehJun 23.2009 — Yes if they don't mention the most common value that people mean when they refer to Julian Date - which is CCYYDDD (so today is 2009174).

The Julian day is of course 2455006.[/QUOTE]
I can't believe it took you 4 years to come up with that.
Copy linkTweet thisAlerts:
@macdabbyOct 13.2009 — OK i like the one that was posed that looked like this:

now = new Date;

jd = ((now.valueOf()/86400000) + 2440587.5);

it works perfect except for a couple things.

One is that I use PHP to set up dates with julian dates so that I can easily tell how far apart they are without using much math. that means that i want oct 1st to be the same number whether is 1AM or 11 PM, so that whole noon thing makes me angry.

also, the javascript function doesn't take into consideration what time zone you are in, so i made the following adjustments:

on that long number, i upped it by another .5 (since it's really 2440588 - .5, im taking out the subtraction of the .5)

then where valueOf() is used, i subtracted the timezone offset (now.getTimezoneOffset()*60000)

so my equation is:

now = new Date;

jd = (((now.valueOf()-(now.getTimezoneOffset()*60000))/86400000)) + 2440588);

and i think this syncs up perfectly with my PHP which is:

unixtojd(time());

now converting it back is something else i am working on, and that's a whole nother story ?
×

Success!

Help @balda spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...