It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
How can I retrieve the time portion of a date?
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
System.out.println(dateFormat(date));
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
String time = dateFormat.format(date)
You won't believe:
String result = dateFormat.format(date);
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I need Date with only yyyy-mm-dd format, because DB2 table having 10 precision of date column.
Date date = new Date();
String modifiedDate= new SimpleDateFormat("yyyy-MM-dd").format(date);
This will do.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
For example:
I was able to get the timestamp
String date="123456765343";
final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(Long.parseLong(date)*1000);
Date d = cal.getTime(); // now this reprents the unix timestamp
I would like to have the date looking like this :
14/Mar/2013 6:31:34 PM
You would have to use SimpleDateFormat (and you don't need the Calendar):
Date d = new Date(Long.parseLong(date) * 1000);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy hh:mm:ss a");
System.out.println(sdf.format(d));
You can use SimpleDateFormat to format your date.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm confused how to create based on the date the transaction code in java and mysql, help me.
You just need to get the Date value from System.
There is some way to get it :
Get Date in Java
Filed under: Java, Programming — Leave a comment
30 November 2011
I’ll give you 2 example.
Example 1:
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Calendar cal = Calendar.getInstance();
System.out.println(df.format(cal.getTime()));
Or youcan use Date instead of Calendar, like this:
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date dt = new Date();
System.out.println(sdf.format(dt));
You can manipulate the Date Format.
And after that you can manipulate that value to somehing like your transcation code you want.
Like
Int index = 0
String transcode;
transcode = sdf &index
index +=1
just be more creative.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to save any date type format as user wishes: The date should be saved to the datebase in the format the user has entered (for example mm/dd/yy, dd/mm/yy or yy/dd/mm).
How can I achieve this?
Maybe try it this way.
Store user preferred date format in his profile and all dates in some default format. When you want to show date to user format it according to his preferences like
String userFormat="yy/MM/dd";
SimpleDateFormat sdf = new SimpleDateFormat(userFormat);
Date someDate = new Date();
String formatedDate = sdf.format(someDate);
System.out.println(formatedDate);
But thats just one of options.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
how to get only time from datetime like(2011-04-23 09:30:51:01) in java or javascript or jquery
In Java:
SimpleDateFormat parseFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SS");
SimpleDateFormat printFormat = new SimpleDateFormat("HH:mm:ss");
Date date = parseFormat.parse("2011-04-23 09:30:51:01");
System.out.println(printFormat.format(date)); // prints 09:30:51
Have you seen http://www.quackit.com/javascript/javascript_date_and_time_functions.cfm (or any other JavaScript Date reference)? In particular see the getHours(), getMinutes() and getSeconds() functions.
Other references:
Where can I find documentation on formatting a date in JavaScript?
http://www.elated.com/articles/working-with-dates/
http://www.webdevelopersnotes.com/tips/html/10_ways_to_format_time_and_date_using_javascript.php3
In Javascript,
var d = new Date("2011-04-20 09:30:51:01");
d.getHours(); // => 9
d.getMinutes(); // => 30
d.getSeconds(); // => 51
Full details on Javascript's Date object are here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date