It's been working fine for me for years.
Here's the basics I use:
var ts1=new Time.Moment(ts);
var ts2=Calendar.info(ts1, Time.FORMAT_MEDIUM);
Where ts is the "epoch" time, and then I format the…
Yeah, that works, but the code you referenced in your original post is still broken.
var now = Calendar.moment( {:seconds=>timestamp} );
var tera = Time.now();
var unix = tera.value();
// unix epoc in string
var epoc = unix.format("%d");
var tein = Calendar.info(tera, Time.FORMAT_SHORT);
// local time
localtime = Lang.format("$1$:$2$:$3$",
[tein.hour.format("%2d"), tein.min.format("%02d"), tein.sec.format("%02d")]);
var clockTime = Sys.getClockTime();
var utc = tera.add(new Time.Duration(clockTime.timeZoneOffset*-1));
tein = Calendar.info(utc, Time.FORMAT_SHORT);
// UTC time
utctime = Lang.format("$1$:$2$",
[tein.hour.format("%2d"), tein.min.format("%02d")]);
// any timezone -5 (FROM UTC OFFSET!!!!) for exaple:
wlofs=(-5*3600);
var oo = tera.add(new Time.Duration(wlofs-clockTime.timeZoneOffset));
var tim = Calendar.info(oo, Time.FORMAT_SHORT);
ftim = Lang.format("$1$:$2$",
[tim.hour.format("%2d"), tim.min.format("%02d")]);
var now = Time.Gregorian.moment({:year=>0,:month=>0,:day=>0}); //Moment with value of 0
var offset = new Time.Duration( epoch );
now = now.add( offset );
Here ya go. ("epoch" is the value for the "epoch tine")Incidently..Sys.println(epoch);
var now = new Toybox.Time.Moment(epoch);
var today = Calendar.info(now, Time.FORMAT_SHORT);
Sys.println(Lang.format("$1$ $2$ $3$", [today.month, today.day,today.year]));
Sys.println(Lang.format("$1$:$2$:$3$",[today.hour, today.min.format("%02d"),today.sec.format("%02d")]));
And the results are:
1428567577
2 5 2126
23:28:16
update. if I use now=Time.now() to get the local tome, and display it (now.value()) , it's with a few hundred second of the "epoch" value I display above. And using the same code for "now" as shown above, it results in the same data and time.
function myExample(epoch) {
Sys.println(epoch);
var now = new Toybox.Time.Moment(epoch);
var today = Calendar.info(now, Time.FORMAT_SHORT);
Sys.println(Lang.format("$1$ $2$ $3$", [today.month, today.day,today.year]));
Sys.println(Lang.format("$1$:$2$:$3$",[today.hour, today.min.format("%02d"),today.sec.format("%02d")]));
}
1428567577
12 31 1989
10:00:00
1428567577
12 31 1989
10:00:00
1428567577
2 6 2126
1:28:16
It's been working fine for me for years.
Here's the basics I use:
var ts1=new Time.Moment(ts);
var ts2=Calendar.info(ts1, Time.FORMAT_MEDIUM);
Where ts is the "epoch" time, and then I format the time based on whats in ts2.
That was 6 years ago. What I posted today is how to do it.