Solved

Java: how to get the date/time

Posted on 2014-02-04
2
307 Views
Last Modified: 2014-02-10
Hello,
  I have to run a dynamic query to get data from 12:00AM of the current day to the current date/time.

I know how to current date/time . How do I get the start of the day . The format should be
'YYYY -MM-DDThh:mm:ss.nnnZ' e.g 2014-02-04T00:00:00.000Z

Thanks for your help
0
Comment
Question by:SiemensSEN
2 Comments
 
LVL 35

Accepted Solution

by:
mccarl earned 200 total points
ID: 39834200
Depending on exactly what you will do with it, something like the following should work...
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date startOfDay = cal.getTime();

Open in new window

The format should be ...
The format is only specified when you convert the Date value to a String value. If you are using anything like JDBC (or a higher level abstraction) you should be passing your Date values (or a similar type) directly to the API for running your query. You shouldn't need to be converting it to a String. If this isn't clear, can you post the code of how you are running your query and I can be more specific.
0
 
LVL 6

Expert Comment

by:Mahesh Bhutkar
ID: 39834897
In short you want a data for current date.  Any reason for time format?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to dynamically set the form action using jQuery.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now