PurpleTalk Fresher Interview Questions – Part – II
In this blog we are discussing about PurpleTalk Fresher Interview Questions – Part – II in a detailed manner with various examples . Some of them are :
Already we have discussed some problems in the previous session blog PurpleTalk Fresher Interview Questions – Part – I . So we explain few more examples for further questions .
REFERENCE : PurpleTalk Fresher Interview Questions – Part – I
https://payilagam.com/blogs/purpletalk-fresher-interview-questions-part-i/
_______________________________________________________________________________________
1. Write a program to
i) Add Two Dates
ii) Convert String to Date
1 . C# Program to Add Two Dates
This C# Program Adds Two Dates . Here the new date is found by adding using function AddDays().
Here is source code of the C# Program to Add Two Dates . The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
- /*
- * C# Program to Add Two Dates
- */
- using System;
- namespace DateAndTime
- {
- class Program
- {
- static int Main()
- {
- DateTime SDate = new DateTime(2018, 2, 9);
- Console.WriteLine(“Starting Date : {0}”, SDate);
- DateTime EDate = startDate.AddDays(9);
- Console.WriteLine(“Ending Date : {0}\n”, EDate);
- Console.ReadLine();
- return 0;
- }
- }
- }
Here is the output of the C# Program:
Starting Date : 2/9/2018 12:00:00 AM
Ending Date : 2/9/2018 12:00:00 AM
____________________________________________________________________
3. Java String to Date Example
Let’s see the simple code to convert String to Date in java.
- importtext.SimpleDateFormat;
- importutil.Date;
- publicclass StringToDateExample1 {
- publicstatic void main(String[] args)throws Exception {
- String sDate1=”31/12/2018″;
- Date date1=new SimpleDateFormat(“dd/MM/yyyy”).parse(sDate1);
- out.println(sDate1+”\t”+date1);
- }
- }
- import java.text.SimpleDateFormat;
- import java.util.Date;
- public class StringToDateExample2 {
- public static void main(String[] args)throws Exception {
- String sDate1=”31/12/2018″;
- String sDate2 = “31-Dec-2018”;
- String sDate3 = “12 31, 1018”;
- String sDate4 = “Mon, Dec 31 2018”;
- String sDate5 = “Mon, Dec 31 2018 23:37:50”;
- String sDate6 = “31-Dec-2018 23:37:50”;
- SimpleDateFormat formatter1=new SimpleDateFormat(“dd/MM/yyyy”);
- SimpleDateFormat formatter2=new SimpleDateFormat(“dd-MMM-yyyy”);
- SimpleDateFormat formatter3=new SimpleDateFormat(“MM dd, yyyy”);
- SimpleDateFormat formatter4=new SimpleDateFormat(“E, MMM dd yyyy”);
- SimpleDateFormat formatter5=new SimpleDateFormat(“E, MMM dd yyyy HH:mm:ss”);
- SimpleDateFormat formatter6=new SimpleDateFormat(“dd-MMM-yyyy HH:mm:ss”);
- Date date1=formatter1.parse(sDate1);
- Date date2=formatter2.parse(sDate2);
- Date date3=formatter3.parse(sDate3);
- Date date4=formatter4.parse(sDate4);
- Date date5=formatter5.parse(sDate5);
- Date date6=formatter6.parse(sDate6);
- System.out.println(sDate1+”\t”+date1);
- System.out.println(sDate2+”\t”+date2);
- System.out.println(sDate3+”\t”+date3);
- System.out.println(sDate4+”\t”+date4);
- System.out.println(sDate5+”\t”+date5);
- System.out.println(sDate6+”\t”+date6);
- }
- }
Output:
31/12/2018 Mon Dec 31
00:00:00 IST 2018
31-Dec-2018 Mon Dec 31
00:00:00 IST 2018 12 31, 2018 Mon Dec 31
00:00:00 IST 2018 Mon , Dec 31 2018 Mon Dec 31
00:00:00 IST 1998 Mon , Dec 31 2018
23:37:50 Mon Dec 31 23:37:50 IST 2018
31-Dec-2018 23:37:50 Mon Dec 31
23:37:50 IST 2018
_______________________________________________________________________________