[codenameone-discussions] Re: Cannot get date from MS

2018-03-13 Thread Gareth Murfin
Doh!!! what an idiot I am, man... Thanks Shai!!

On Tuesday, March 13, 2018 at 1:03:04 PM UTC+8, Shai Almog wrote:
>
> You are getting seconds not milliseconds.
>

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to codenameone-discussions+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/73a40aa8-e2c5-4805-b083-9c0c0ee9ad14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[codenameone-discussions] Re: Cannot get date from MS

2018-03-12 Thread Shai Almog
You are getting seconds not milliseconds.

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to codenameone-discussions+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/12f187a5-3b5f-4e88-8ea9-360230a08ca9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[codenameone-discussions] Re: Cannot get date from MS

2018-03-11 Thread Gareth Murfin
I noticed that the ms from System.currentMillis has 3 extra digits, ie 

1520835640781   from system.currentimemillis
1520764777  from api im using

so I assume I just need to add some value to the one that is giving me 
errors? Think ive done this before but i cannot recall what I need to add.

On Monday, March 12, 2018 at 2:18:07 PM UTC+8, Gareth Murfin wrote:
>
> I have all sorts of methods ive made over the years for making date 
> strings, but they dont seem to work now. Everytime I pass in ms they come 
> up with 1970. 
>
> Example:  1520764749 on this website (
> https://www.freeformatter.com/epoch-timestamp-to-date-converter.html) 
> shows 3/11/2018, 6:39:37 PM
>
> but if I pass it into any of my methods I always get 18/01/1970. Am I 
> doing somethign wrong or has there somehow been a new bug introduced into 
> the Data class?
>
> public static String getDateString(Date d)
> {
> if (d==null)
> {
> _("*warning* date passed in was null, we will assume that this 
> is 'now' and make a new one");
> d= new Date();
> }
> //formulate this date objects
> SimpleDateFormat df = new SimpleDateFormat();
> //we want: 2016-11-21T15:47:21+00:00
>// String dateString = df.format("-MM-dd hh:mm:ss a", d);
>df.applyPattern("-MM-dd hh:mm:ss a");//PROBABLY WRONG AFTER CN1 
> CONVERSION
> String dateString = df.format( d);
>/// _("dateString is ->"+dateString);
> return dateString.toString();
> }
>   //takes a date object in and returns a string like 19/09/2011
> public static String getDateString_(Date d)
> {
> Calendar calendar = null;
> calendar = Calendar.getInstance();
> calendar.setTime(d);
> String day= calendar.get(Calendar.DAY_OF_MONTH)+"";
> String month  = (calendar.get(Calendar.MONTH)+1)+""; //month 
> starts at 0 in java
> if (month.length()==1)
> {
> month="0"+month; // getthe zero before or it looks odd
> }
> String year   = calendar.get(Calendar.YEAR)+"";
> return day+"/"+month+"/"+year;
> }
> 
>  public static String getDateString__(Date date)
>   {
> Calendar cal = Calendar.getInstance();
> cal.setTime(date);
> int year= cal.get(Calendar.YEAR);
> int month   = cal.get(Calendar.MONTH);
> int day = cal.get(Calendar.DAY_OF_MONTH);
> 
> String writeme = day+"/"+month+"/"+year;
> //old way was this, so we cna test 
> //REMOVE THIS, ONLY PUT IT BACK IN FOR TESTING BACKWARDS
> //OLD WAY NOT IN USE ANYMORE writeme = day+"-"+month+"-"+year;
> 
> _("getDateString__ returning "+writeme);
> return writeme;
>   }
> 
>  
> //takes a date object in and returns a string like 19/09/2011
> public static String getDateString___(Date d)
> {
> Calendar calendar = null;
> calendar = Calendar.getInstance();
> 
> calendar.setTime(d);
> 
> String day= calendar.get(Calendar.DAY_OF_MONTH)+"";
> String month  = (calendar.get(Calendar.MONTH)+1)+""; //month 
> starts at 0 in java
> if (month.length()==1)
> {
> month="0"+month; // getthe zero before or it looks odd
> }
> String year   = calendar.get(Calendar.YEAR)+"";
> 
> return day+"/"+month+"/"+year;
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to codenameone-discussions+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/5b544bd7-495d-4e39-8b2b-5972d85caab4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.