Groovy web console

subscribe to the feed Subscribe
to this
site

date format

Published 2 weeks ago by Ram with tags data format
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
import java.text.SimpleDateFormat
Date date = new Date();
     //   String formatDate = new SimpleDateFormat("yyyy-MM-dd")
     //   String formatTime = new SimpleDateFormat("HH:mm:ss.SSS")

def formatDate = new SimpleDateFormat("yyyy-MM-dd")
            formatDate.setTimeZone(TimeZone.getTimeZone("UTC"));
        def anDate = formatDate.format(date)

def formatTime = new SimpleDateFormat("HH:mm:ss.SSS'Z'")
    formatTime.setTimeZone(TimeZone.getTimeZone("UTC"));
        def anTime = formatTime.format(date)
    
String date1 = anDate + "T" + anTime

//    formatDate.setTimeZone(TimeZone.getTimeZone("UTC"));
  //      def anDate = formatDate.format(date)
        //formatTime.setTimeZone(TimeZone.getTimeZone("UTC"));
 //       def anTime = formatTime.format(date)
//String dateFormat = formatDate + "T" + formatTime
//dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
     //   def anTime = formatDate.format(date)