?
Solved

Return formatted time

Posted on 2012-04-01
9
Medium Priority
?
545 Views
Last Modified: 2012-04-10
Im trying to get the time a button is pressed and display it on the
screen


case R.id.btoMovies:
                       statuschange.setText("To Movies");
                       mystatus="2";
                       Time now = new Time();
                       now.setToNow();
                       timeofchange.setText("" + now);

Open in new window

and it returns 20120401T232303GMT(0,91,0,0,1333322583)

Im trying to get the time formatted  YYYYMMDDTHHMMSS format  ... is
this the best way to do this ?
0
Comment
Question by:dolamitejenkins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 37794459
I think SImpleDateFormat will work with Androiud as elsewhere in java

http://developer.android.com/reference/java/text/SimpleDateFormat.html
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37794464
So

I think somethidk like that should work:

SimpleDateFormat sdf = new SimpleDateFormat(" "yyyyMMddHHmmssSSSZ":

java.util.Date dd = new java.util.Date();

.setText(sdf.format(dd));
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37794475
This is the test:
SimpleDateFormat sdf0401 = new SimpleDateFormat("yyyyMMddHHmmss");

java.util.Date dd0401 = new java.util.Date();


        System.out.println(sdf0401.format(dd0401));

Open in new window


Output:

20120401204808

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

Expert Comment

by:for_yan
ID: 37794478
If you want to have "T" in between, then you probably want to do it this way:

SimpleDateFormat sdf0401 = new SimpleDateFormat("yyyyMMdd");

        SimpleDateFormat sdf0402 = new SimpleDateFormat("HHmmss");

java.util.Date dd0401 = new java.util.Date();


        System.out.println(sdf0401.format(dd0401) +"T"+sdf0402.format(dd0401));

Open in new window



20120401T205121

Open in new window

0
 

Author Comment

by:dolamitejenkins
ID: 37794510
its keeps crashing android

04-02 04:04:48.368: E/AndroidRuntime(306):       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

04-02 04:04:48.368: E/AndroidRuntime(306):       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

I cant really see the error because eclipse is tough to debug in /
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37794561
I tried using SimpleDateFormat and java.util.Date
in the HelloAndroid project and it worked fine in the emulator


package com.exmple.helloandroid;

import java.text.SimpleDateFormat;

import android.app.Activity;
import android.os.Bundle;
import android.text.Layout;
import android.widget.TableLayout;
import android.widget.TextView;

public class HelloAndroidActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TextView tv = new TextView(this);
        
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
     
     java.util.Date dd = new java.util.Date();
     
              
        tv.setText("Hello, absolutely new Android,  " + sdf.format(dd));
        setContentView(tv);
        

       // setContentView(R.layout.main);
    }
}

Open in new window

0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 37794574
androis with time
0
 

Author Comment

by:dolamitejenkins
ID: 37794575
Thank you that worked ....
0
 

Author Closing Comment

by:dolamitejenkins
ID: 37830763
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question