Date And Timestamp

Name: _____________________

Date: _____________________

Instructions: Answer all questions. Write your answers clearly in the space provided.

Question 1:

How many methods does the DateTime class have?

A. 8
B. 9
C. 10
D. 11
Answer: _________
Question 2:

How many constants does the DateTime class have?

A. 8
B. 9
C. 10
D. 11
Answer: _________
Question 3:

Which method is simply an object-oriented version of date()?

A. DateTime::format()
B. DateTime::modify()
C. DateTime::setTime()
D. DateTime::setDate()
Answer: _________
Question 4:

Among the four PHP DateTimeZone classes given below how many are static?
1. listAbbreviations()
2. getName()
3. getOffset()
4. listIdentifiers()

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 5:

Among the four PHP DateTimeZone classes given below how many are nonstatic?
1. _construct()
2. getName()
3. getOffset()
4. getTransitions()

A. 1
B. 2
C. 3
D. 4
Answer: _________
Question 6:

Which method enables you to calculate whether daylight saving time is in force at a specific date and time?

A. getOffset()
B. getTranitions()
C. ISODate()
D. savingTime()
Answer: _________
Question 7:

Which of the following functions do not return a timestamp? 1. time() 2. date() 3. strtotime() 4. localtime() 5. gmmktime()

A. Option 1 and 5
B. Option 3 and 4
C. Option 1 and 4
D. Option 2 and 4
Answer: _________
Question 8:

The getdate() function returns

A. An integer
B. A floating-point number
C. An array
D. A string
Answer: _________
Question 9:

.......... Returns the time of sunrise for a given day / location.

A. datesunrise()
B. date_sunrise()
C. date-sunrise()
D. date.sunrise()
Answer: _________
Question 10:

................Checks a date for numeric validity.

A. check_date
B. verifydate
C. Verify_date
D. checkdate
Answer: _________
Question 11:

What is the difference, in seconds, between the current timestamp in the GMT time zone and the current timestamp in your local time zone?

A. It depends on the number of hours between the local time zone and GMT
B. There is no difference
C. The two will only match if the local time zone is GMT
D. The two will never match
Answer: _________
Question 12:

You must make a call to ................... to specify what time zone you want calculations to take place in before calling any date functions.

A. date_default_timezone_set()
B. datedefault_timezone_set()
C. date_defaulttimezone_set()
D. date_default_timezoneset()
Answer: _________
Question 13:

The ......... function parses an English textual date or time into a Unix timestamp.

A. strtodate()
B. stroftime()
C. strtotime()
D. str_to_time()
Answer: _________
Question 14:

................ Formats a local time or date according to locale settings.

A. strftime
B. strgtime
C. strhtime
D. stritime
Answer: _________
Question 15:

The date() function returns ___ representation of the current date and/or time.

A. Integer
B. String
C. Boolean
D. Float
Answer: _________
Question 16:

Which one of the following format parameter can be used to identify timezone?

A. T
B. N
C. E
D. I
Answer: _________
Question 17:

What will be the output of the following code? If say date is 22/06/2013. <?php echo "Today is " .date( "F d, Y" ) ?>

A. Today is 22 June, 2013
B. Today is 22-06-2013
C. Today is 06-22-2013
D. Today is June 22, 2013
Answer: _________
Question 18:

Which one of the following function is useful for producing a timestamp based on a given date and time.

A. time()
B. mktime()
C. mrtime()
D. mtime()
Answer: _________
Question 19:

Which function displays the web page’s most recent modification date?

A. lastmod()
B. getlastmod()
C. last_mod()
D. get_last_mod()
Answer: _________
Question 20:

What will be the output of the following PHP code? If say date is 22/06/2013. <?php printf( date( "t" ) ) ?>

A. 30
B. 22
C. JUNE
D. 2013
Answer: _________
Question 21:

Say you want to calculate the date 45 days from the present date which one of the following statement will you use?

A. totime(“+45”)
B. totime(“+45 days”)
C. strtotime(“+45 days”)
D. strtotime(“-45 days”)
Answer: _________
Question 22:

To create an object and set the date to JUNE 22, 2013, which one of the following statement should be executed?

A. $date = Date(“22 JUNE 2013”)
B. $date = new Date(“JUNE 22 2013”)
C. $date = DateTime(“22 JUNE 2013”)
D. $date = new DateTime(“22 JUNE 2013”)
Answer: _________
Question 23:

What will be the output of the following PHP code? <?php echo (checkdate( 4,31,2010 ) ? 'Valid' : 'Invalid' )

?>

A. TRUE
B. FALSE
C. Valid
D. Invalid
Answer: _________
Question 24:

If the format is F then which one of the following will be returned?

A. Complete text representation of month
B. Day of month, with leading zero
C. Daylight saving time
D. Day of month, without zeros
Answer: _________
Question 25:

What will the following script output? <?php $time = strtotime ( '2004/01/01' )
echo date ( 'H:i:s', $time )
?>

A. 0:00:00
B. 12:00:00
C. 00:i:00
D. 12:i:00
Answer: _________
Question 26:

What would happen if the following script were run on a Windows server set to Moscow, Russia’s time zone? <?php echo gmmktime ( 0, 0, 0, 1, 1, 1970 )
?>

A. It would output the number 0
B. It would output the number -1
C. It would output the number 1
D. It would raise an error
Answer: _________
Question 27:

Which of the following is the right way to use the DateTime class?

A. $date = get_Class(DateTime)
B. $date = class DateTime
C. $date = new DateTime()
D. $date = new class DateTime()
Answer: _________
Question 28:

What will be the output of the following PHP code if date is 24/02/2008? <?php $date = new DateTime ()
echo $date- > format( 'l,F,js,Y' ) ?>

A. Sunday, February 24th 2008
B. Sunday, 02 24 2008
C. Sunday, 24 02 2008
D. Sunday, 24th February 2008
Answer: _________
Question 29:

Which of the following statements can be used to set the time zone in individual scripts?

A. date_set_timezone(‘Europe/London’)
B. date_default_timezone_set(‘Europe/London’)
C. date_set_default_timezone(‘Europe/London’)
D. date_default_timezone(‘Europe/London’)
Answer: _________
Question 30:

Which of the following statements can be used to add two months to the existing date?

A. $date->modify(‘+2 months’)
B. $date = modify(‘+2 months’)
C. $date = modify(‘2+ months’)
D. $date->modify(‘2+ months’)
Answer: _________

Answer Key

1: B
Solution: The DateTime class has nine methods, all of which are public.
2: D
Solution: The DateTime class has 11 constants, no static properties or methods.
3: A
Solution: The format() method is simply an object-oriented version of date(). It takes $dateFormat as an argument. $dateFormat is a string consisting of the same date formatting characters accepted by the procedural date() function.
4: B
Solution: listAbbreviations() and listIdentifiers() are static methods.
5: D
Solution: All of the given methods are non static.
6: B
Solution: This outputs a multidimensional array listing past and future changes to the offset from UTC for a DateTimeZone object.
7: D
8: C
9: B
10: D
11: B
12: A
13: C
14: A
15: B
Solution: The prototype of this function is: string date(string format [, int timestamp]).
16: C
Solution: When the format is E the timezone is identified and returned…example America/New_York.
17: D
Solution: F is the parameter for complete text representation of month, d for day of month, and Y for 4 digit representation of year.
18: B
19: B
Solution: The getlastmod() function returns the value of the page’s Last Modified header or FALSE in the case of an error.
20: A
Solution: The t parameter is used to determine the number of days in the current month.
21: C
Solution: The strtotime() function and GNU date syntax is used to calculating the date x days from the present date.
22: D
Solution: The dateTime() method is class constructor. You can set the date either at the time of instantiation or later by using a variety of mutators.
23: D
Solution: April has 30 days and the above date is 31 therefore Invalid is returned.
24: A
Solution: Day of month, with leading zero is represented by D

Daylight saving time by I

Day of month, without zeros by j.
25: C
26: B
27: C
Solution: The way you use the DateTime class is like any other class: instantiate an object, and store it in a variable.
28: A
Solution: The format() method displays the date in same way as standard date function().
29: B
Solution: You can also use ini_set(‘date.timezone’, ‘Europe/London’)
.
30: A
Solution: To change the date stored by a DateTime object after it has been created, you use DateTime::modify() with a natural language expression.