- Clojure - Libraries
- Clojure - Automated Testing
- Clojure - Applications
- Clojure - Concurrent Programming
- Clojure - Java Interface
- Clojure - Databases
- Clojure - Reference Values
- Clojure - Macros
- Clojure - Watchers
- Clojure - Agents
- Clojure - StructMaps
- Clojure - Metadata
- Clojure - Atoms
- Clojure - Date & Time
- Clojure - Destructuring
- Clojure - Predicates
- Clojure - Regular Expressions
- Clojure - Sequences
- Clojure - Exception Handling
- Clojure - Namespaces
- Clojure - Maps
- Clojure - Vectors
- Clojure - Sets
- Clojure - Lists
- Clojure - Strings
- Clojure - File I/O
- Clojure - Recursion
- Clojure - Numbers
- Clojure - Functions
- Clojure - Decision Making
- Clojure - Loops
- Clojure - Operators
- Clojure - Variables
- Clojure - Data Types
- Clojure - REPL
- Clojure - Basic Syntax
- Clojure - Environment
- Clojure - Overview
- Clojure - Home
Clojure Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Clojure - Date and Time
Since the Clojure framework is derived from Java classes, one can use the date-time classes available in Java in Clojure. The class date represents a specific instant in time, with milpsecond precision.
Following are the methods available for the date-time class.
java.util.Date
This is used to create the date object in Clojure.
Syntax
Following is the syntax.
java.util.Date.
Parameters − None.
Return Value − Allocates a Date object and initiapzes it so that it represents the time at which it was allocated, measured to the nearest milpsecond.
Example
An example on how this is used is shown in the following program.
(ns example) (defn Example [] (def date (.toString (java.util.Date.))) (println date)) (Example)
Output
The above program produces the following output. This will depend on the current date and time on the system, on which the program is being run.
Tue Mar 01 06:11:17 UTC 2016
java.text.SimpleDateFormat
This is used to format the date output.
Syntax
Following is the syntax.
(java.text.SimpleDateFormat. format dt)
Parameters − ‘format’ is the format to be used when formatting the date. ‘dt’ is the date which needs to be formatted.
Return Value − A formatted date output.
Example
An example on how this is used is shown in the following program.
(ns example) (defn Example [] (def date (.format (java.text.SimpleDateFormat. "MM/dd/yyyy") (new java.util.Date))) (println date)) (Example)
Output
The above program produces the following output. This will depend on the current date and time on the system, on which the program is being run.
03/01/2016
getTime
Returns the number of milpseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
Syntax
Following is the syntax.
(.getTime)
Parameters − None.
Return Value − The number of milpseconds since January 1, 1970, 00:00:00 GMT represented by this date.
Example
An example on how this is used is shown in the following program.
(ns example) (import java.util.Date) (defn Example [] (def date (.getTime (java.util.Date.))) (println date)) (Example)
Output
The above program produces the following output. This will depend on the current date and time on the system, on which the program is being run.
1456812778160Advertisements