How do i create a timestamp (for a ref no) using a bean?

Posted on 2005-02-25
Medium Priority
Last Modified: 2010-04-01
I have a reference number which i want to set to for example:

If the user is an employee then the first letter starts with E followed by "-date" then "_time"
T -for Technician, A -for Administrator.

//---------------------------here is my timestampbean-----------------------------------------
  public String getTime()
    return this.time + "";
  public void setTime(String myTime)
    hrs = myTime.substring(0, 1);
    mins = myTime.substring(3, 4);
    myTime = hrs + "" + mins;
    this.time = myTime;
  public String getDate()
    return this.date;
  public void setDate(String myDate)//--date format passed in is: 25/02/05
    day = myDate.substring(0, 1);
    month = myDate.substring(3, 4);
    year = myDate.substring(5, 6);
    myDate = day + "-" + month + "-" + year; //type-25-02-05_time
    this.date = myDate;
  public String getType()
    return type;
  public void setType(String myType)//--date format passed in is: 25/02/05
    myType = myType.substring(0, 1);
    this.type = myType;
  public String getTimeStamp()
    return getType() + "-" + getDate() + "_" + getTime();
//-------------------here is where i call set methods in the jsp-----------------------------
      String time = DoDateTime(new java.util.Date(), java.text.DateFormat.SHORT, java.util.Locale.UK);
      String date = DoTime(new java.util.Date(), java.text.DateFormat.SHORT, java.util.Locale.UK);
      String type = loginBeanId.getType();
      String timeStamp = timeStampBeanId.getTimeStamp();
the setDate method won't work, it causes index out of bounds error.

This is what displays in the ref no textfield: Technician-null_2/

What is wrong with this stupid code?
My brain is fried so please help.
Question by:mccoole
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment

Accepted Solution

kiranhk earned 500 total points
ID: 13406942
if you just want your date to be in this format dd-mm-yy then use the date formatter to get it instead of using index substring
or you can just say string replaceall for the date passed

import java.text.*;

Format formatter = new SimpleDateFormat("dd-MMM-yy");
String date = (Date)formatter.parse("29-Jan-02").toString();




Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Hey fellow admins! This time, I have a little fairy tale for you. As many tales do, it starts boring and then gets pretty gory. I hope you like it. TL;DR: It is about an important security matter, you should read it if you run or administer Windows …
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

777 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