Dates

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class Untitled {
    @Before
    public void setUp() throws Exception {
        selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.ebay.in/");
        selenium.start();
    }

    @Test
    public void testUntitled() throws Exception {
        String start_date =
selenium.getEval("var d = new Date();var curr_date = d.getDate()-2;if(curr_date.toString().length!=2) curr_date = '0'+curr_date ;var curr_month = d.getMonth(); curr_month = curr_month + 1;if(curr_month.toString().length!=2) curr_month= '0'+curr_month;curr_date + '-'+ curr_month + '-'+10;");
        String end_date = selenium.getEval("var d = new Date();var curr_date = d.getDate();if(curr_date.toString().length!=2) curr_date = '0'+curr_date ;var curr_month = d.getMonth(); curr_month = curr_month + 1;if(curr_month.toString().length!=2) curr_month= '0'+curr_month;curr_date + '-'+ curr_month + '-'+10;");
        System.out.println(start_date);
        System.out.println(end_date);
    }

    @After
    public void tearDown() throws Exception {
        selenium.stop();
    }
}



Current Time

 import java.util.*;

public class CurrentTime{
public static void main(String[] args){

Calendar calendar = new GregorianCalendar();
String am_pm;
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
 
if(calendar.get(Calendar.AM_PM) == 0)
am_pm = "AM";
else
am_pm = "PM";
 
System.out.println("Current Time : " + hour + ":" + minute + ":" + second + " " + am_pm);
}
}

1 comment: