This example we will show you how to Display Month name in MMM format. To display month name in java we will have two ways
With Formatter class
import java.util.Calendar;
import java.util.Formatter;
public class Test{
public static void main(String args[]) {
Formatter fmt = new Formatter();
Calendar cal = Calendar.getInstance();
fmt = new Formatter();
fmt.format("%tB %tb %tm", cal, cal, cal);
System.out.println(fmt);
}
}
|
Output:
April Apr 04
With SimpleDateFormat
package com.rrtutors.lib;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Test {
public static void main(String[] args) {
SimpleDateFormat f = new SimpleDateFormat("MMM");
SimpleDateFormat f1 = new SimpleDateFormat("dd");
SimpleDateFormat f2 = new SimpleDateFormat("a");
int h;
if(Calendar.getInstance().get(Calendar.HOUR)== 0)h = 12;
else h = Calendar.getInstance().get(Calendar.HOUR);
String filename="Current Date is :"
+" "+f1.format(new Date())
+" "+f.format(new Date())
+" "+h+f2.format(new Date());
System.out.println(filename);
}
}
|
Output:
Current Date is : 05 Apr 10PM
JAVA File IO examples
JAVA Date & Time Progamming Examples
JAVA Collections
var = "Python Programming"What is the output of print var?
Ruby program to add two integer numbers
how to create an array with Array.[](*args) in Ruby ?
What are the various Ruby runtimes, and how are they different?
Ruby program to check whether the given number is prime or not
Ruby program to reverse a string
Ruby program to check whether the given number is palindrome
Ruby program to print Fibonacci series
How to Replace array elements in Ruby?
Ruby program to print an array
Ruby program to check whether the given number is Armstrong
Program to Print Triangle of Numbers in Ruby
How to add/remove elements to Array in Ruby?
How to shuffle an array in Ruby?
Creating Array with Array.new(size, obj) in Ruby
Ruby program to generate random numbers
Ruby program to Calculate the factorial of given number
What are #method_missing and #send? Why are they useful?
How to Sort Array in Ruby?
How to get index of array element in Ruby
How to Get Input with Gets in Ruby
How to create two dimensional array in ruby?