JavaScript DateTime vs .NET Date Time

Hello,

I am writing a WinForms application in C#. It hosts a Web Browser control that will display offline HTML content.

I need to calculate the following:
 - Day of the year (1 to 366: 366 for leap years)
 - Week of the Year (1 to 52: Didn't check but can some years have a 53rd week?)

Considering that I have access to the DOM, an easy way to do this is what I have done right now:
 - Place markers in the JavaScript code e.g. (var dayOfYear = ~~~DAYOFYEAR~~~;)
 - Before loading the HTML, replace the markers with calculated values from C# (html = html.Replace("~~~DAYOFYEAR~~~", System.DateTime.Now.SomeProperty);)
 - Load the HTML through the DOM

I'm doing this only because I don't have too much experience with JavaScript. I did check the Date class but did not find any direct ways to calculate this. Any ideas?

Out of context:
Also, instead of saving loading HTML files directly from the hard drive, I load the URL "abount:blank" and set set the document.body.innetHTML at runtime. This way, users cannot access the HTML/JavaScript code by doing a "View Source". This approach works fine until relative image paths are used. Since the file loaded does not have a valid location, should I use absolute image paths? Is that the best approach?

Thanks,

Khan
raheelasadkhanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mvan01Commented:
For the out of context question, that's an interesting idea.  How about starting off (in the head, or top of the body, or even just before the firs relative path):

<base href="http://www.yourdomain.com/zero_or_more/directories/">

Useful, if you've never encountered it before.  :-)

Peace and joy.  mvan
0
mvan01Commented:
... By the way, base href= works for loading .js files too!  Peace and joy.  mvan
0
mvan01Commented:
For the weekofyear in JavaScript, check this.  I'll bet you can get the day of year out of the calc. too.  :-)

http:Q_21214747.html#12636650

Peace and joy.  mvan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

raheelasadkhanAuthor Commented:
@mvan10: Regading the relative issue, I've nver come across this approach before and it sounds good. Will give it a try and let you know.

With respect to the real question, I have already considered the approachyou mentioned and was wondering if JavaScript offers an easier way to do this...
0
mvan01Commented:
Nah, don't think so.  Maybe over a few days I can search around for a tight JavaScript routine, but that one seems typical.

Peace and joy.  mvan
0
raheelasadkhanAuthor Commented:
Thanks again. Calculating the values with math is no issue. I'll figure that out. I was wondering if there was built in support for this kind of stuff in JavaScript.
0
mvan01Commented:
Hi Khan,

You are welcome.  I'm glad I could help a bit.  JavaScript does not have the built in support.  If you've little experience with JS, then have a look here.  This page is for the Date properties, but is an excellent reference site for JS programming:

http://www.javascriptkit.com/jsref/date.shtml

And as I said, the base href= is quite useful, esp. for testing code, but also to short-hand the otherwise req'd absolute paths.  You can even switch from one to another throughout the page, if need be.

I hope your project works out well.  Peace and joy.  mvan
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.