Programming, website development forum Get latest updates by RSS Follow TechnicalTalk on Twitter Follow TechnicalTalk on Facebook 
HomeSearchRecent PostsLoginRegisterContact Us

Username  
Password    
  Forgot your password?  

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

Current Date and time using Java

 
webmaster forum
nikon  Offline
Activity
0%
 
New Coder
Posts: 20
Topics: 13
September 11, 2008, 07:28:33 PM

hello all

I want to fetch current date and time using java in java applet so i can implement in my html page using applet. How can I do that?

Please help
 
webmaster forum
polas  Offline
Activity
33.33%
 
Code Guru
Gender: Male
Posts: 1399
Topics: 85
WWW
September 12, 2008, 02:39:26 AM

using java.util.Calendar

 int year = cal.get(Calendar.YEAR);
  int month = cal.get(Calendar.MONTH);
  int date = cal.get(Calendar.DATE);

Have a look at :

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html

Mesham Type Oriented Parallel Programming Language, Free online technical support
 
webmaster forum
Activity
0%
 
New Coder
Posts: 49
Topics: 14
September 16, 2008, 03:33:48 AM

Hi with the use of Util.Calendar you can get the current Date and Time. Below is the code sample.

import java.util.Calendar;
import java.text.SimpleDateFormat;

public class DateUtils {
  public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";

  public static String now() {
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
    return sdf.format(cal.getTime());

  }

  public static void  main(String arg[]) {
    System.out.println("Now : " + DateUtils.now());
  }
}



use the below link to know more details

http://www.javafaq.nu/java-example-code-288.html
http://www.rgagnon.com/javadetails/java-0106.html
 
webmaster forum
vijay12  Offline
Activity
0%
 
Regular Coder
Posts: 67
Topics: 33
January 03, 2009, 11:43:13 AM

Hi friend. Its easy to get the current date and time using Java. Take a look here, http://www.roseindia.net/java/java-get-example/get-date-now.shtml to get the source code.
« Last Edit: January 03, 2009, 12:07:44 PM by theone759 »
 
webmaster forum
Activity
0%
 
New Coder
Posts: 41
Topics: 0
WWW
September 23, 2011, 06:44:54 AM

nice link provide perfect date and time code

Display Banner | Pull Up Banner
 
webmaster forum
polas  Offline
Activity
33.33%
 
Code Guru
Gender: Male
Posts: 1399
Topics: 85
WWW
September 29, 2011, 02:36:47 PM

new Date() is even easier, if you want ms since the epoch then new Date().getTime();

Simple!

Mesham Type Oriented Parallel Programming Language, Free online technical support
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.15 | SMF © 2011, Simple Machines


Google visited last this page February 04, 2012, 02:07:38 AM