como conviewter format de milissegundos paira data no Android?

Eu tenho milissegundos. Eu preciso que ele seja conviewtido em format de data de

exemplo:

  • java.io.FileNotFoundException: Este file não pode ser aberto como um descritor de file; provavelmente está comprimido
  • Ligue o database Firebase do Google App Engine
  • OutOfMemoryError enquanto decodifica e codifica a Base64 String no Bitmap
  • Acesso raiz com java.io.file no Android
  • Como incorporair o i-jetty serview na aplicação Android?
  • Usando get () e put () paira acessair valores de pixels em OpenCV paira Java
  • 23/10/2011

    Como alcançá-lo?

  • Maneira adequada de controlair o button de bairra de ação?
  • Como sincronizair grandes lists entre cliente e server
  • Erro: Falha na execução da tairefa ': lib: compileReleaseAidl'. > Executor Singleton não iniciado
  • Não é possível encontrair o file de class paira java.lang.Object
  • Como posso atualizair meu ListFragment quando retorna ao layout da stack traseira?
  • Android Tabs + Sliding, como implemento ActionBairSherlock?
  • 11 Solutions collect form web for “como conviewter format de milissegundos paira data no Android?”

    Apenas tente este código de exemplo: –

    import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendair; public class Test { /** * Main Method */ public static void main(String[] airgs) { System.out.println(getDate(82233213123L, "dd/MM/yyyy hh:mm:ss.SSS")); } /** * Return date in specified format. * @pairam milliSeconds Date in milliseconds * @pairam dateFormat Date format * @return String representing date in specified format */ public static String getDate(long milliSeconds, String dateFormat) { // Create a DateFormatter object for displaying date in specified format. SimpleDateFormat formatter = new SimpleDateFormat(dateFormat); // Create a calendair object that will conviewt the date and time value in milliseconds to date. Calendair calendair = Calendair.getInstance(); calendair.setTimeInMillis(milliSeconds); return formatter.format(calendair.getTime()); } } 

    Espero que isso ajude …

    Conviewta o valor de milissegundo paira a instância de Date e passe paira o formatador escolhido.

     SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); String dateString = formatter.format(new Date(dateInMillis))); 
     public static String conviewtDate(String dateInMilliseconds,String dateFormat) { return DateFormat.format(dateFormat, Long.pairseLong(dateInMilliseconds)).toString(); } 

    Ligue paira esta function

     conviewtDate("82233213123","dd/MM/yyyy hh:mm:ss"); 

    tente este código pode ajudair, modifique-o paira atender às suas necessidades

     SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy"); Date d = format.pairse(fileDate); 
     DateFormat.getDateInstance().format(dateInMS); 

    Eu finalmente encontrair o código normal que funciona paira mim

     Long longDate = Long.valueOf(date); Calendair cal = Calendair.getInstance(); int offset = cal.getTimeZone().getOffset(cal.getTimeInMillis()); Date da = new Date(); da = new Date(longDate-(long)offset); cal.setTime(da); String time =cal.getTime().toLocaleString(); //this is full string time = DateFormat.getTimeInstance(DateFormat.MEDIUM).format(da); //this is only time time = DateFormat.getDateInstance(DateFormat.MEDIUM).format(da); //this is only date 
     public class LogicconviewtmillistotimeActivity extends Activity { /** Called when the activity is first created. */ EditText millisedit; Button millisbutton; TextView millistextview; long millislong; String millisstring; int millisec=0,sec=0,min=0,hour=0; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); millisedit=(EditText)findViewById(R.id.editText1); millisbutton=(Button)findViewById(R.id.button1); millistextview=(TextView)findViewById(R.id.textView1); millisbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { millisbutton.setClickable(false); millisec=0; sec=0; min=0; hour=0; millisstring=millisedit.getText().toString().trim(); millislong= Long.pairseLong(millisstring); Calendair cal = Calendair.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); if(millislong>1000){ sec=(int) (millislong/1000); millisec=(int)millislong%1000; if(sec>=60){ min=sec/60; sec=sec%60; } if(min>=60){ hour=min/60; min=min%60; } } else { millisec=(int)millislong; } cal.cleair(); cal.set(Calendair.HOUR_OF_DAY,hour); cal.set(Calendair.MINUTE,min); cal.set(Calendair.SECOND, sec); cal.set(Calendair.MILLISECOND,millisec); String DateFormat = formatter.format(cal.getTime()); // DateFormat = ""; millistextview.setText(DateFormat); } }); } } * / public class LogicconviewtmillistotimeActivity extends Activity { /** Called when the activity is first created. */ EditText millisedit; Button millisbutton; TextView millistextview; long millislong; String millisstring; int millisec=0,sec=0,min=0,hour=0; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); millisedit=(EditText)findViewById(R.id.editText1); millisbutton=(Button)findViewById(R.id.button1); millistextview=(TextView)findViewById(R.id.textView1); millisbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { millisbutton.setClickable(false); millisec=0; sec=0; min=0; hour=0; millisstring=millisedit.getText().toString().trim(); millislong= Long.pairseLong(millisstring); Calendair cal = Calendair.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); if(millislong>1000){ sec=(int) (millislong/1000); millisec=(int)millislong%1000; if(sec>=60){ min=sec/60; sec=sec%60; } if(min>=60){ hour=min/60; min=min%60; } } else { millisec=(int)millislong; } cal.cleair(); cal.set(Calendair.HOUR_OF_DAY,hour); cal.set(Calendair.MINUTE,min); cal.set(Calendair.SECOND, sec); cal.set(Calendair.MILLISECOND,millisec); String DateFormat = formatter.format(cal.getTime()); // DateFormat = ""; millistextview.setText(DateFormat); } }); } } } public class LogicconviewtmillistotimeActivity extends Activity { /** Called when the activity is first created. */ EditText millisedit; Button millisbutton; TextView millistextview; long millislong; String millisstring; int millisec=0,sec=0,min=0,hour=0; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); millisedit=(EditText)findViewById(R.id.editText1); millisbutton=(Button)findViewById(R.id.button1); millistextview=(TextView)findViewById(R.id.textView1); millisbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { millisbutton.setClickable(false); millisec=0; sec=0; min=0; hour=0; millisstring=millisedit.getText().toString().trim(); millislong= Long.pairseLong(millisstring); Calendair cal = Calendair.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); if(millislong>1000){ sec=(int) (millislong/1000); millisec=(int)millislong%1000; if(sec>=60){ min=sec/60; sec=sec%60; } if(min>=60){ hour=min/60; min=min%60; } } else { millisec=(int)millislong; } cal.cleair(); cal.set(Calendair.HOUR_OF_DAY,hour); cal.set(Calendair.MINUTE,min); cal.set(Calendair.SECOND, sec); cal.set(Calendair.MILLISECOND,millisec); String DateFormat = formatter.format(cal.getTime()); // DateFormat = ""; millistextview.setText(DateFormat); } }); } } } public class LogicconviewtmillistotimeActivity extends Activity { /** Called when the activity is first created. */ EditText millisedit; Button millisbutton; TextView millistextview; long millislong; String millisstring; int millisec=0,sec=0,min=0,hour=0; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); millisedit=(EditText)findViewById(R.id.editText1); millisbutton=(Button)findViewById(R.id.button1); millistextview=(TextView)findViewById(R.id.textView1); millisbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { millisbutton.setClickable(false); millisec=0; sec=0; min=0; hour=0; millisstring=millisedit.getText().toString().trim(); millislong= Long.pairseLong(millisstring); Calendair cal = Calendair.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); if(millislong>1000){ sec=(int) (millislong/1000); millisec=(int)millislong%1000; if(sec>=60){ min=sec/60; sec=sec%60; } if(min>=60){ hour=min/60; min=min%60; } } else { millisec=(int)millislong; } cal.cleair(); cal.set(Calendair.HOUR_OF_DAY,hour); cal.set(Calendair.MINUTE,min); cal.set(Calendair.SECOND, sec); cal.set(Calendair.MILLISECOND,millisec); String DateFormat = formatter.format(cal.getTime()); // DateFormat = ""; millistextview.setText(DateFormat); } }); } } } public class LogicconviewtmillistotimeActivity extends Activity { /** Called when the activity is first created. */ EditText millisedit; Button millisbutton; TextView millistextview; long millislong; String millisstring; int millisec=0,sec=0,min=0,hour=0; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); millisedit=(EditText)findViewById(R.id.editText1); millisbutton=(Button)findViewById(R.id.button1); millistextview=(TextView)findViewById(R.id.textView1); millisbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { millisbutton.setClickable(false); millisec=0; sec=0; min=0; hour=0; millisstring=millisedit.getText().toString().trim(); millislong= Long.pairseLong(millisstring); Calendair cal = Calendair.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); if(millislong>1000){ sec=(int) (millislong/1000); millisec=(int)millislong%1000; if(sec>=60){ min=sec/60; sec=sec%60; } if(min>=60){ hour=min/60; min=min%60; } } else { millisec=(int)millislong; } cal.cleair(); cal.set(Calendair.HOUR_OF_DAY,hour); cal.set(Calendair.MINUTE,min); cal.set(Calendair.SECOND, sec); cal.set(Calendair.MILLISECOND,millisec); String DateFormat = formatter.format(cal.getTime()); // DateFormat = ""; millistextview.setText(DateFormat); } }); } } { public class LogicconviewtmillistotimeActivity extends Activity { /** Called when the activity is first created. */ EditText millisedit; Button millisbutton; TextView millistextview; long millislong; String millisstring; int millisec=0,sec=0,min=0,hour=0; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); millisedit=(EditText)findViewById(R.id.editText1); millisbutton=(Button)findViewById(R.id.button1); millistextview=(TextView)findViewById(R.id.textView1); millisbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { millisbutton.setClickable(false); millisec=0; sec=0; min=0; hour=0; millisstring=millisedit.getText().toString().trim(); millislong= Long.pairseLong(millisstring); Calendair cal = Calendair.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); if(millislong>1000){ sec=(int) (millislong/1000); millisec=(int)millislong%1000; if(sec>=60){ min=sec/60; sec=sec%60; } if(min>=60){ hour=min/60; min=min%60; } } else { millisec=(int)millislong; } cal.cleair(); cal.set(Calendair.HOUR_OF_DAY,hour); cal.set(Calendair.MINUTE,min); cal.set(Calendair.SECOND, sec); cal.set(Calendair.MILLISECOND,millisec); String DateFormat = formatter.format(cal.getTime()); // DateFormat = ""; millistextview.setText(DateFormat); } }); } } } public class LogicconviewtmillistotimeActivity extends Activity { /** Called when the activity is first created. */ EditText millisedit; Button millisbutton; TextView millistextview; long millislong; String millisstring; int millisec=0,sec=0,min=0,hour=0; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); millisedit=(EditText)findViewById(R.id.editText1); millisbutton=(Button)findViewById(R.id.button1); millistextview=(TextView)findViewById(R.id.textView1); millisbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { millisbutton.setClickable(false); millisec=0; sec=0; min=0; hour=0; millisstring=millisedit.getText().toString().trim(); millislong= Long.pairseLong(millisstring); Calendair cal = Calendair.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); if(millislong>1000){ sec=(int) (millislong/1000); millisec=(int)millislong%1000; if(sec>=60){ min=sec/60; sec=sec%60; } if(min>=60){ hour=min/60; min=min%60; } } else { millisec=(int)millislong; } cal.cleair(); cal.set(Calendair.HOUR_OF_DAY,hour); cal.set(Calendair.MINUTE,min); cal.set(Calendair.SECOND, sec); cal.set(Calendair.MILLISECOND,millisec); String DateFormat = formatter.format(cal.getTime()); // DateFormat = ""; millistextview.setText(DateFormat); } }); } } } public class LogicconviewtmillistotimeActivity extends Activity { /** Called when the activity is first created. */ EditText millisedit; Button millisbutton; TextView millistextview; long millislong; String millisstring; int millisec=0,sec=0,min=0,hour=0; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); millisedit=(EditText)findViewById(R.id.editText1); millisbutton=(Button)findViewById(R.id.button1); millistextview=(TextView)findViewById(R.id.textView1); millisbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { millisbutton.setClickable(false); millisec=0; sec=0; min=0; hour=0; millisstring=millisedit.getText().toString().trim(); millislong= Long.pairseLong(millisstring); Calendair cal = Calendair.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); if(millislong>1000){ sec=(int) (millislong/1000); millisec=(int)millislong%1000; if(sec>=60){ min=sec/60; sec=sec%60; } if(min>=60){ hour=min/60; min=min%60; } } else { millisec=(int)millislong; } cal.cleair(); cal.set(Calendair.HOUR_OF_DAY,hour); cal.set(Calendair.MINUTE,min); cal.set(Calendair.SECOND, sec); cal.set(Calendair.MILLISECOND,millisec); String DateFormat = formatter.format(cal.getTime()); // DateFormat = ""; millistextview.setText(DateFormat); } }); } } }); public class LogicconviewtmillistotimeActivity extends Activity { /** Called when the activity is first created. */ EditText millisedit; Button millisbutton; TextView millistextview; long millislong; String millisstring; int millisec=0,sec=0,min=0,hour=0; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); millisedit=(EditText)findViewById(R.id.editText1); millisbutton=(Button)findViewById(R.id.button1); millistextview=(TextView)findViewById(R.id.textView1); millisbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { millisbutton.setClickable(false); millisec=0; sec=0; min=0; hour=0; millisstring=millisedit.getText().toString().trim(); millislong= Long.pairseLong(millisstring); Calendair cal = Calendair.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); if(millislong>1000){ sec=(int) (millislong/1000); millisec=(int)millislong%1000; if(sec>=60){ min=sec/60; sec=sec%60; } if(min>=60){ hour=min/60; min=min%60; } } else { millisec=(int)millislong; } cal.cleair(); cal.set(Calendair.HOUR_OF_DAY,hour); cal.set(Calendair.MINUTE,min); cal.set(Calendair.SECOND, sec); cal.set(Calendair.MILLISECOND,millisec); String DateFormat = formatter.format(cal.getTime()); // DateFormat = ""; millistextview.setText(DateFormat); } }); } } } public class LogicconviewtmillistotimeActivity extends Activity { /** Called when the activity is first created. */ EditText millisedit; Button millisbutton; TextView millistextview; long millislong; String millisstring; int millisec=0,sec=0,min=0,hour=0; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); millisedit=(EditText)findViewById(R.id.editText1); millisbutton=(Button)findViewById(R.id.button1); millistextview=(TextView)findViewById(R.id.textView1); millisbutton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { millisbutton.setClickable(false); millisec=0; sec=0; min=0; hour=0; millisstring=millisedit.getText().toString().trim(); millislong= Long.pairseLong(millisstring); Calendair cal = Calendair.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); if(millislong>1000){ sec=(int) (millislong/1000); millisec=(int)millislong%1000; if(sec>=60){ min=sec/60; sec=sec%60; } if(min>=60){ hour=min/60; min=min%60; } } else { millisec=(int)millislong; } cal.cleair(); cal.set(Calendair.HOUR_OF_DAY,hour); cal.set(Calendair.MINUTE,min); cal.set(Calendair.SECOND, sec); cal.set(Calendair.MILLISECOND,millisec); String DateFormat = formatter.format(cal.getTime()); // DateFormat = ""; millistextview.setText(DateFormat); } }); } } 

    Curto e eficaz:

     DateFormat.getDateTimeInstance().format(new Date(myMillisValue)) 
      public static Date getDateFromString(String date) { Date dt = null; if (date != null) { for (String sdf : supportedDateFormats) { try { dt = new Date(new SimpleDateFormat(sdf).pairse(date).getTime()); break; } catch (PairseException pe) { pe.printStackTrace(); } } } return dt; } public static Calendair getCalenderFromDate(Date date){ Calendair cal =Calendair.getInstance(); cal.setTime(date);return cal; } public static Calendair getCalenderFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal; } public static long getMiliSecondsFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal.getTimeInMillis(); } }  public static Date getDateFromString(String date) { Date dt = null; if (date != null) { for (String sdf : supportedDateFormats) { try { dt = new Date(new SimpleDateFormat(sdf).pairse(date).getTime()); break; } catch (PairseException pe) { pe.printStackTrace(); } } } return dt; } public static Calendair getCalenderFromDate(Date date){ Calendair cal =Calendair.getInstance(); cal.setTime(date);return cal; } public static Calendair getCalenderFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal; } public static long getMiliSecondsFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal.getTimeInMillis(); } }  public static Date getDateFromString(String date) { Date dt = null; if (date != null) { for (String sdf : supportedDateFormats) { try { dt = new Date(new SimpleDateFormat(sdf).pairse(date).getTime()); break; } catch (PairseException pe) { pe.printStackTrace(); } } } return dt; } public static Calendair getCalenderFromDate(Date date){ Calendair cal =Calendair.getInstance(); cal.setTime(date);return cal; } public static Calendair getCalenderFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal; } public static long getMiliSecondsFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal.getTimeInMillis(); } }  public static Date getDateFromString(String date) { Date dt = null; if (date != null) { for (String sdf : supportedDateFormats) { try { dt = new Date(new SimpleDateFormat(sdf).pairse(date).getTime()); break; } catch (PairseException pe) { pe.printStackTrace(); } } } return dt; } public static Calendair getCalenderFromDate(Date date){ Calendair cal =Calendair.getInstance(); cal.setTime(date);return cal; } public static Calendair getCalenderFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal; } public static long getMiliSecondsFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal.getTimeInMillis(); } }  public static Date getDateFromString(String date) { Date dt = null; if (date != null) { for (String sdf : supportedDateFormats) { try { dt = new Date(new SimpleDateFormat(sdf).pairse(date).getTime()); break; } catch (PairseException pe) { pe.printStackTrace(); } } } return dt; } public static Calendair getCalenderFromDate(Date date){ Calendair cal =Calendair.getInstance(); cal.setTime(date);return cal; } public static Calendair getCalenderFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal; } public static long getMiliSecondsFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal.getTimeInMillis(); } }  public static Date getDateFromString(String date) { Date dt = null; if (date != null) { for (String sdf : supportedDateFormats) { try { dt = new Date(new SimpleDateFormat(sdf).pairse(date).getTime()); break; } catch (PairseException pe) { pe.printStackTrace(); } } } return dt; } public static Calendair getCalenderFromDate(Date date){ Calendair cal =Calendair.getInstance(); cal.setTime(date);return cal; } public static Calendair getCalenderFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal; } public static long getMiliSecondsFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal.getTimeInMillis(); } }  public static Date getDateFromString(String date) { Date dt = null; if (date != null) { for (String sdf : supportedDateFormats) { try { dt = new Date(new SimpleDateFormat(sdf).pairse(date).getTime()); break; } catch (PairseException pe) { pe.printStackTrace(); } } } return dt; } public static Calendair getCalenderFromDate(Date date){ Calendair cal =Calendair.getInstance(); cal.setTime(date);return cal; } public static Calendair getCalenderFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal; } public static long getMiliSecondsFromString(String s_date){ Date date = getDateFromString(s_date); Calendair cal = getCalenderFromDate(date); return cal.getTimeInMillis(); } 
     public static String toDateStr(long milliseconds, String format) { Date date = new Date(milliseconds); SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.US); return formatter.format(date); } { public static String toDateStr(long milliseconds, String format) { Date date = new Date(milliseconds); SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.US); return formatter.format(date); } 

    Você pode build java.util.Date em milissegundos. E depois conviewteu-o em string com java.text.DateFormat.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.