0% found this document useful (0 votes)
2 views4 pages

Date Time Converter Tool

The document outlines a JSP-based Date Time Converter application that allows users to input a date, time, and select a timezone to convert to UTC. It includes a form for user input, a corresponding POJO class to handle the data, and an action class that processes the conversion and handles errors. Additionally, the action class saves the conversion results to a database using a DAO class.

Uploaded by

Sachin Chauhan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Date Time Converter Tool

The document outlines a JSP-based Date Time Converter application that allows users to input a date, time, and select a timezone to convert to UTC. It includes a form for user input, a corresponding POJO class to handle the data, and an action class that processes the conversion and handles errors. Additionally, the action class saves the conversion results to a database using a DAO class.

Uploaded by

Sachin Chauhan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

JSP

<%@ page contentType="text/html;charset=UTF-8" %>


<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
<head>
<title>Date Time Converter</title>
</head>
<body>
<h2>Date Time Converter</h2>

<s:form action="convertDateTime" method="post" model="form">


<s:textfield label="Date (YYYY-MM-DD)" name="inputDate" />
<s:textfield label="Time (HH:MM:SS)" name="inputTime" />

<s:select label="Timezone" name="selectedTimeZone" headerKey=""


headerValue="Select Timezone"
list="#{'UTC':'UTC', 'America/New_York':'America/New_York',
'Europe/London':'Europe/London'}" />

<s:submit value="Convert" />


</s:form>

<s:if test="hasErrors()">
<div style="color: red;">
<s:actionerror />
</div>
</s:if>

<s:if test="[Link] != null">


<div>
<b>UTC Date and Time:</b> <s:property value="[Link]" />
</div>
</s:if>
</body>
</html>

POJO...............................................................................
..................................................
import [Link];

public class DateTimeConverterForm {


private String inputDate;
private String inputTime;
private String selectedTimeZone;
private String utcDateTime;
private List<String> timeZoneList;

// Getters and setters for all the properties

public String getInputDate() {


return inputDate;
}

public void setInputDate(String inputDate) {


[Link] = inputDate;
}
public String getInputTime() {
return inputTime;
}

public void setInputTime(String inputTime) {


[Link] = inputTime;
}

public String getSelectedTimeZone() {


return selectedTimeZone;
}

public void setSelectedTimeZone(String selectedTimeZone) {


[Link] = selectedTimeZone;
}

public String getUtcDateTime() {


return utcDateTime;
}

public void setUtcDateTime(String utcDateTime) {


[Link] = utcDateTime;
}

public List<String> getTimeZoneList() {


return timeZoneList;
}

public void setTimeZoneList(List<String> timeZoneList) {


[Link] = timeZoneList;
}
}
Action.............................................................................
.......................................................
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

@Action(value = "convertDateTime", results = {


@Result(name = "success", location = "/[Link]"),
@Result(name = "error", location = "/[Link]")
})
public class DateTimeConverterAction extends ActionSupport {
private DateTimeConverterForm form = new DateTimeConverterForm();

public String execute() {


try {
String inputDateTimeStr = [Link]() + " " +
[Link]();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
[Link]([Link]([Link]()));

Date inputDateObj = [Link](inputDateTimeStr);


long utcMillis = [Link]() -
[Link]([Link]()).getRawOffset();
Date utcDate = new Date(utcMillis);

[Link]([Link](utcDate) + " UTC");

// Save the conversion result to the database using DAO


DateTimeConverterDAO dateTimeConverterDAO = new DateTimeConverterDAO();
[Link]([Link](),
[Link](), [Link](), [Link]());
} catch (ParseException e) {
addActionError("Error parsing date/time: " + [Link]());
return ERROR;
}

return SUCCESS;
}

// Getters and setters for the form


public DateTimeConverterForm getForm() {
return form;
}

public void setForm(DateTimeConverterForm form) {


[Link] = form;
}
}

DAO................................................................................
....................................................
import [Link];
import [Link];
import [Link];

public class DateTimeConverterAction extends ActionSupport {


// Existing code...

public String execute() {


try {
String inputDateTimeStr = [Link]() + " " +
[Link]();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
[Link]([Link]([Link]()));

Date inputDateObj = [Link](inputDateTimeStr);


long utcMillis = [Link]() -
[Link]([Link]()).getRawOffset();
Date utcDate = new Date(utcMillis);

[Link]([Link](utcDate) + " UTC");

// Save the conversion result to the database using DAO


DateTimeConverterDAO dateTimeConverterDAO = new DateTimeConverterDAO();
[Link]([Link](),
[Link](), [Link](), [Link]());
} catch (Exception e) {
addActionError("Error processing date/time: " + [Link]());
return ERROR;
}

return SUCCESS;
}

// Existing code...
}

Action.............................................................................
....................................

You might also like