Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #7565

Re: SimpleDateFormat

Date 2011-09-04 22:18 -0400
From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: SimpleDateFormat
References <d25d19e9-5818-4e42-a035-3da993ac56d0@z8g2000yqe.googlegroups.com>
Message-ID <4e64318c$0$305$14726298@news.sunsite.dk> (permalink)
Organization SunSITE.dk - Supporting Open source

Show all headers | View raw


On 9/4/2011 9:14 PM, bob wrote:
> Anyone know how to use SimpleDateFormat to get a lowercase am and pm?

Code snippet:

import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Date;

public class AMPM {
	public static void main(String[] args) {
		Date d1 = new Date();
		Date d2 = new Date(d1.getTime() + 12*60*60*1000L);
		SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a");
		System.out.println(sdf.format(d1));
		System.out.println(sdf.format(d2));
		DateFormatSymbols sym = sdf.getDateFormatSymbols();
		sym.setAmPmStrings(new String[] { "am", "pm" });
		sdf.setDateFormatSymbols(sym);
		System.out.println(sdf.format(d1));
		System.out.println(sdf.format(d2));
	}
}

Arne

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

SimpleDateFormat bob <bob@coolgroups.com> - 2011-09-04 18:14 -0700
  Re: SimpleDateFormat Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-04 21:22 -0400
    Re: SimpleDateFormat Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-04 22:30 -0400
  Re: SimpleDateFormat Arne Vajhøj <arne@vajhoej.dk> - 2011-09-04 22:18 -0400
  Re: SimpleDateFormat Roedy Green <see_website@mindprod.com.invalid> - 2011-09-05 11:12 -0700
    Re: SimpleDateFormat Lew <lewbloch@gmail.com> - 2011-09-05 13:11 -0700
      Re: SimpleDateFormat Roedy Green <see_website@mindprod.com.invalid> - 2011-09-05 15:57 -0700
        Re: SimpleDateFormat Arne Vajhøj <arne@vajhoej.dk> - 2011-09-05 19:38 -0400
        Re: SimpleDateFormat Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-05 19:38 -0400
          Re: SimpleDateFormat Roedy Green <see_website@mindprod.com.invalid> - 2011-09-14 18:27 -0700
            Re: SimpleDateFormat Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-14 21:38 -0400
              Re: SimpleDateFormat RedGrittyBrick <RedGrittyBrick@spamweary.invalid> - 2011-09-15 14:32 +0100
        Re: SimpleDateFormat markspace <-@.> - 2011-09-05 16:49 -0700
        Re: SimpleDateFormat Lew <lewbloch@gmail.com> - 2011-09-05 17:34 -0700
    Re: SimpleDateFormat Arne Vajhøj <arne@vajhoej.dk> - 2011-09-05 16:37 -0400

csiph-web