Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2005-02-25
1
Medium Priority
?
196 Views
Last Modified: 2010-04-01
I have a reference number which i want to set to for example:
   E-25-02-05_1759
   T-25-02-05_1759

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);
      timeStampBeanId.setTime(time);
      //timeStampBeanId.setDate(date);
      String type = loginBeanId.getType();
      timeStampBeanId.setType(type);
      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.
0
Comment
Question by:mccoole
1 Comment
 
LVL 8

Accepted Solution

by:
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();


or

passedDate.replaceAll("/","-");


http://javaalmanac.com/egs/java.text/ParseDate.html
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

What happened when I tried to make my phone, a Samsung Galaxy S8, stop dropping all WiFi signals was a saga I won't repeat here, but what you might want to know is how it started and how I got it working again.
The number of companies understanding the potential of IoT on B2B market is growing with each day. And yet only a small share of IoT developers have managed to equalize incomes and stay competitive in the international market.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

572 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