Headertab

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Monday 20 November 2017

Date formate java and android

Letter  Date or Time Component  Presentation    Examples
G       Era designator          Text                AD
y       Year                    Year                1996; 96
M       Month in year           Month               July; Jul; 07
w       Week in year            Number              27
W       Week in month           Number              2
D       Day in year             Number              189
d       Day in month            Number              10
F       Day of week in month    Number              2
E       Day in week             Text                Tuesday; Tue
a       Am/pm marker            Text                PM
H       Hour in day (0-23)      Number              0
k       Hour in day (1-24)      Number              24
K       Hour in am/pm (0-11)    Number              0
h       Hour in am/pm (1-12)    Number              12
m       Minute in hour          Number              30
s       Second in minute        Number              55
S       Millisecond             Number              978
z       Time zone               General time zone   Pacific Standard Time; PST; GMT-08:00
Z       Time zone               RFC 822 time zone   -0800 

1:

try {
    String dateString = "30/09/2014";
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    Date date = sdf.parse(dateString);

    long startDate = date.getTime();

} catch (ParseException e) {
    e.printStackTrace();

}

2:


public static void main(String[] args) throws ParseException {
    java.util.Date fecha = new java.util.Date("Mon Dec 15 00:00:00 CST 2014");
    DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.US);
    Date date;
    date = (Date)formatter.parse(fecha.toString());
    System.out.println(date);        

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    String formatedDate = cal.get(Calendar.DATE) + "/" + 
            (cal.get(Calendar.MONTH) + 1) + 
            "/" +         cal.get(Calendar.YEAR);
    System.out.println("formatedDate : " + formatedDate);
}

3:

String dateStr = "Mon Jun 18 00:00:00 IST 2012";
DateFormat formatter = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy");
Date date = (Date)formatter.parse(dateStr);
System.out.println(date);        

Calendar cal = Calendar.getInstance();
cal.setTime(date);
String formatedDate = cal.get(Calendar.DATE) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" +         cal.get(Calendar.YEAR);
System.out.println("formatedDate : " + formatedDate);

4:


System.out.println("Date: "+ String.valueOf(new Date()));
    SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String stringdate = dt.format(new Date());
    System.out.println("String.valueOf(date): "+stringdate);

    try {
    Date date = dt.parse(stringdate);
    System.out.println("parse date: "+ String.valueOf(date));
    } catch (ParseException e) {
    e.printStackTrace();
    }

5:

java.util.Date date1 = new Date("11/19/2015"); 
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd yyyy HH:mma");
String format = formatter.format(date);
System.out.println(format);

6:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
                Date date = new Date();
                Date date1 = new Date();
            try {
                System.out.println("Date1:   "+date1);
                System.out.println("date" + date);

                date = simpleDateFormat.parse("01-01-2013");
                date1 = simpleDateFormat.parse("06-15-2013");

                System.out.println("Date1 is:"+date1);
                System.out.println("date" + date);

            } catch (Exception e) {
                System.out.println(e.getMessage());
            }

7:

String newstr = "08/16/2011";
SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat format = new SimpleDateFormat("EE MMM dd hh:mm:ss z yyyy");
Calendar c = Calendar.getInstance();
c.setTime(format1.parse(newstr));
System.out.println(format.format(c.getTime()));

8:

public static String getDayFromDateString(String stringDate,String dateTimeFormat)
{
    String[] daysArray = new String[] {"saturday","sunday","monday","tuesday","wednesday","thursday","friday"};
    String day = "";

    int dayOfWeek =0;
    //dateTimeFormat = yyyy-MM-dd HH:mm:ss
    SimpleDateFormat formatter = new SimpleDateFormat(dateTimeFormat);
    Date date;
    try {
        date = formatter.parse(stringDate);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        dayOfWeek = c.get(Calendar.DAY_OF_WEEK)-1;
        if (dayOfWeek < 0) {
            dayOfWeek += 7;
        }
        day = daysArray[dayOfWeek];
    } catch (Exception e) {
        e.printStackTrace();
    }

    return day;
}

9:

String dayOfTheWeek           = (String) DateFormat.format("EEEE", date); // Thursday
String day                             = (String) DateFormat.format("dd",   date); // 20
String monthString               = (String) DateFormat.format("MMM",  date); // Jun
String monthNumber           = (String) DateFormat.format("MM",   date); // 06
String year                            = (String) DateFormat.format("yyyy", date); // 2013

10:

Thank you



Thursday 16 November 2017

ShimmerLayout in android

Hello friends

Today we are learn about how to create Shimmer layout in android basically shimmer layout use when data is loading so the best solution here. follow some easy step and enjoy with code...


MainActivity.java

package com.samset.androidshimmerlayout;

import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.samset.samsetshimmerlayout.views.ShimmerRecyclerView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ShimmerRecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView = findViewById(R.id.recycler_view);
        recyclerView.showShimmerAdapter();

        recyclerView.postDelayed(new Runnable() {
            @Override
            public void run() {
                //recyclerView.hideShimmerAdapter();
                recyclerView.setAdapter(new ShimmerAdapter(MainActivity.this));
            }
        }, 10000);
    }


    public class ShimmerAdapter extends RecyclerView.Adapter<ShimmerAdapter.MyViewHolder> {
        private Context context;

        public ShimmerAdapter(Context ctx) {
            this.context = ctx;
        }

        @Override
        public int getItemCount() {
            return 20;
        }

        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            LayoutInflater inflater = LayoutInflater.from(context);
            View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_item, parent, false);
            return new MyViewHolder(itemView);

        }

        @Override
        public void onBindViewHolder(final MyViewHolder holder, final int position) {
                holder.container.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent=new Intent(MainActivity.this,SecondActivity.class);
                        startActivity(intent);
                    }
                });
        }


        public class MyViewHolder extends RecyclerView.ViewHolder {
            LinearLayout container;


            public MyViewHolder(View view) {
                super(view);
                container = view.findViewById(R.id.llcontainer);

            }
        }

    }

}




activitymain.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.samset.androidshimmerlayout.MainActivity">

    <com.samset.samsetshimmerlayout.views.ShimmerRecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:demo_child_count="10"
        app:demo_layout="@layout/recyclerview_shimmer"
        app:demo_layout_manager_type="linear_vertical" />

</android.support.constraint.ConstraintLayout>



Thank you
If you want full source code click this linkShimmerLayout-master


Live Sample