Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6773925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:43:33+00:00 2026-05-26T15:43:33+00:00

I want to get my dates into a format like this: 2010-10-01 How do

  • 0

I want to get my dates into a format like this: 2010-10-01

How do I do this?

Also, I grabbed this from another question:

use (groovy.time.TimeCategory) {

Date date = Date.parse("dd-MMM-yyyy", "15-Mar-2011")

def months = (0..11).collect { 
    (date + it.months).format("MMM/yyyy") 
}

}

How would I change the output of this script to the format I specified above? Thanks:)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:43:33+00:00Added an answer on May 26, 2026 at 3:43 pm

    In order to parse it out from a String:

    Date.parse( "yyyy-M-d", "2010-10-01" )
    

    In order to format the date that you already have:

    def yourDate= new GregorianCalendar( 2010, Calendar.OCTOBER, 1 )
    
    assert String.format('%tY-%<tm-%<td', yourDate) == '2010-10-01'
    

    EDIT (to answer the comment)

    groovy:000> yourDate= new GregorianCalendar( 2010, Calendar.OCTOBER, 1 )
    ===> java.util.GregorianCalendar[...]
    groovy:000> print String.format('%tY-%<tm-%<td', yourDate)
    2010-10-01===> null
    groovy:000>
    

    and backwards:

    groovy:000> Date.parse( "yyyy-M-d", String.format('%tY-%<tm-%<td', yourDate) )
    ===> Fri Oct 01 00:00:00 EDT 2010
    

    current date:

    groovy:000> yourDate = Calendar.instance
    ===> java.util.GregorianCalendar[..]
    groovy:000> print String.format('%tY-%<tm-%<td', yourDate) 
    2011-11-03===> null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get all the objects from the list and put them into
I just want to get the total days in a list of dates. Here
I have some date and I want to get last x day before this
I'm trying to get the date into a string in C#. I want the
I'm failing a bit to get this working. I read out a date from
I have a date formatted like this from a Java Server: YYYY/MM/DD 00:00:00.0 And
By way of introduction... I've run into this question: Difference between 2 adjacent fields
I want to get week Start Date of a week. I am able to
I want to get models whom date is within a date range. So I
I want to get value in a date picker and add to textfield_date..I used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.