473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Date() confusion

I have a value representing seconds since epoch (the number of seconds
since midnight Jan 1, 1970).

I want to disply this as Month, Day, and Year: MMM-DD-YYYY.

I've read about the Date() object but I am a bit confused.... How do I
get the year given seconds since epoch?

Thanks,

--Yan
Apr 20 '06 #1
4 2624
Captain Dondo wrote:
I have a value representing seconds since epoch (the number of seconds
since midnight Jan 1, 1970).

I want to disply this as Month, Day, and Year: MMM-DD-YYYY.

I've read about the Date() object but I am a bit confused.... How do I
get the year given seconds since epoch?
Javascript Date Object uses Milliseconds from the epoch

Thanks,

--Yan


var NumOfSeconds = 1145554709;
var NumOfMilliSeconds = NumOfSeconds*1000;
D = new Date(NumOfMilliSeconds);

var Month = D.getMonth()+1;
var Day = D.getDate();
var Year = D.getFullYear();
var DateString = Month+"-"+Day+"-"+Year;
alert(DateString);

Apr 20 '06 #2
Captain Dondo wrote:
I have a value representing seconds since epoch (the number of seconds
since midnight Jan 1, 1970).

I want to disply this as Month, Day, and Year: MMM-DD-YYYY.

I've read about the Date() object but I am a bit confused.... How do I
get the year given seconds since epoch?
Javascript Date Object uses Milliseconds from the epoch

Thanks,

--Yan


var NumOfSeconds = 1145554709;
var NumOfMilliSeconds = NumOfSeconds*1000;
D = new Date(NumOfMilliSeconds);

var Month = D.getMonth()+1;
var Day = D.getDate();
var Year = D.getFullYear();
var DateString = Month+"-"+Day+"-"+Year;
alert(DateString);

- JS
http://www.endeavorpub.com

Apr 20 '06 #3
jshanman wrote:
Captain Dondo wrote:
I have a value representing seconds since epoch (the number of seconds
since midnight Jan 1, 1970).

I want to disply this as Month, Day, and Year: MMM-DD-YYYY.

I've read about the Date() object but I am a bit confused.... How do I
get the year given seconds since epoch?

Javascript Date Object uses Milliseconds from the epoch


Thanks!

I knew it had to be simple.... :-)

--Yan
Apr 20 '06 #4
JRS: In article <12*************@corp.supernews.com>, dated Thu, 20 Apr
2006 10:23:33 remote, seen in news:comp.lang.javascript, Captain Dondo
<ya*@NsOeSiPnAeMr.com> posted :
I have a value representing seconds since epoch (the number of seconds
since midnight Jan 1, 1970).
That's unreasonable or inadequately described; one almost always has
seconds since 1970-01-01 00:00:00 UTC (really GMT), where the TLA is
important. Also, midnight usually means the end of the day - consider
"I'll see you tomorrow, at midnight".
I want to disply this as Month, Day, and Year: MMM-DD-YYYY.
Silly format.
Month needs only two digits, and one writes Mon for the TLA.

I've read about the Date() object but I am a bit confused.... How do I
get the year given seconds since epoch?


But did you read the newsgroup FAQ, as posted Mon/Fri??

You can use

new Date(sec*1e3).getFullYear()
or new Date(sec*1e3).getUTCFullYear()

depending on requirement. If you want the year in a location other than
"Greenwich" or user's local, that's harder, but can always be done if
the TZ string is known - see in my js-date5.htm .

Then the date in proper standard form can be got, for example, with code
(in include1.js, shown in js-nclds.htm) such as resulted in :-

function anonymous() {
/* Date.ISOlocaldateStr YYYY-MM-DD */
with (this)
return getFullYear()+'-'+LZ(getMonth()+1)+'-'+LZ(getDate())
}

or with such as

with (Dobj)
S = String((getFullYear()*100+getMonth()+1)*100+getDat e()).
replace(/(....)(..)(..)/, "$1-$2-$3")
If you must have MMM-DD-YYYY, start with YYYY-MM-DD and adapt it.
-----------
Note to All : my PC was reluctant to boot today. If I seem to vanish,
such could be the cause.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Apr 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: amith | last post by:
hi I have written javascript for comparing two dates in US format and finding out whether the start date is greater than the end date and vice versa. In this attempt i have instantiated the...
3
by: C White | last post by:
got another one for you guys out there, and thanks again for the help with my "counting question" this time i'm looking to select records based on date, the database stores the date as...
3
by: Dino | last post by:
I am creating a website that is going to ask the user to enter a date! then from an access database get all records where a date field is greater then the date entered! Sounds simple, I do it in...
7
by: Gertjan van Heijst | last post by:
Hi, I really hope someone can help me because I've already spend 2 days on this problem and I'm not getting anywhere. I think the problem is that I don't really understand how text boxes store...
7
by: Tony Williams | last post by:
I have a check box called Loadtxt and when it is ticked I want the value of a control called EmailDatetxt to be today's date. I am using this code in the AfterUpdate event of the checkbox but it...
3
by: Gerry Abbott | last post by:
Hi all Im in Ireland, so date format is always dd/mm/yy. It trying use query as a filter for a recordset, containing a date field, SELECT tblInspections.InspDate FROM tblInspections WHERE...
2
by: Bill | last post by:
Question: For a table like this: Date | Description | Amount | Balance 9/25/04 | payment on acct | 25.00 | 0.00 10/1/04 | delivery | 54.25 | 54.25 11/5/04 | payment on...
4
by: djc | last post by:
I am confused with all the options for date values... What should I be using when I want to compare (=, >, <) two dates, not including the time.. for example when inserting data in a database the...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
10
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.