Solved

# How to convert datetime to long value?

Posted on 2006-04-19
681 Views
I wish to use the timestamp class, as the first method is deprecated, I wish to use the second one. What is the common way to convert the year, month, date, hour, minute, second, and nano to a long value?

Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
Deprecated. instead use the constructor Timestamp(long millis)
Timestamp(long time)
Constructs a Timestamp object using a milliseconds time value.
0
Question by:william007

LVL 86

Accepted Solution

Use a Calendar

long time = cal.getTimeInMillis();

(set Cal first of course)
0

LVL 9

Author Comment

Hi, may I know how to set the Calendar with the date information? as I can't see a direct way to do this from the calendar API.
0

LVL 86

Expert Comment

0

LVL 9

Author Comment

Hi, I just miss it, the calendar class has a method
set(int year, int month, int date, int hourOfDay, int minute, int second)

Thanks:-)
0

LVL 23

Expert Comment

0

LVL 86

Expert Comment

:-)
0

## Featured Post

### Suggested Solutions

squareUp  challenge 22 80
countClumps  challenge 10 68
scoresSpecial  challenge 13 34
java continue statement 10 51
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…