Solved

Return formatted time

Posted on 2012-04-01
9
540 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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 500 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
check java version using powershell 13 92
tomcat startup error 5 65
Running JavaFX on JDeveloper 12C 1 32
Convert from a json string array to a Java object 3 32
The case of the missing phone talks about the way a small electronic gadget (the mobile phone) has penetrated into our lives and has made us addicted to it.
Here, we have shared an easy step by step tutorial on how to download instagram images and videos on PC, Android Mobile and iOS mobile.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

773 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